{"problem":{"name":"Replace C or Swap AB","description":{"content":"You are given strings $X$ and $Y$ of length $N$ each, consisting of `A`, `B`, and `C`. Determine if it is possible to make $X$ coincide with $Y$ by performing the following three kinds of operations o","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"arc166_a"},"statements":[{"statement_type":"Markdown","content":"You are given strings $X$ and $Y$ of length $N$ each, consisting of `A`, `B`, and `C`.\nDetermine if it is possible to make $X$ coincide with $Y$ by performing the following three kinds of operations on $X$ any number of times, possibly zero.\n\n*   **Operation (1)**：Choose a character `C` in $X$ and replace it with `A`.\n*   **Operation (2)**：Choose a character `C` in $X$ and replace it with `B`.\n*   **Operation (3)**：Choose a substring `AB` in $X$ and replace it with `BA`. More formally, choose an $i$ such that the $i$\\-th and $(i+1)$\\-th characters of $X$ are `A` and `B`, respectively, and replace the former with `B` and the latter with `A`.\n\nYou have $T$ test cases to solve.\n\n## Constraints\n\n*   $1\\leq T\\leq 2\\times 10^5$\n*   $1\\leq N\\leq 2\\times 10^5$\n*   Each of $X$ and $Y$ is a string of length $N$ consisting of `A`, `B`, and `C`.\n*   The sum of $N$ over the test cases in a single input is at most $2\\times 10^5$.\n\n## Input\n\nThe input is given from Standard Input in the following format:\n\n$T$\n$\\text{case}_1$\n$\\vdots$\n$\\text{case}_T$\n\nEach test case is given in the following format:\n\n$N$ $X$ $Y$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"arc166_a","tags":[],"sample_group":[["6\n3 ABC ABC\n1 C B\n1 B C\n2 AB BA\n2 BA AB\n3 CCB ABA","Yes\nYes\nNo\nYes\nNo\nYes\n\n*   For the first test case, you can perform the operations zero times to make $X$ coincide with $Y$.\n*   For the second test case, you can perform Operation (2) once to make $X$ coincide with $Y$.\n*   For the fourth test case, you can perform Operation (3) once to make $X$ coincide with $Y$.\n*   For the sixth test case, you can perform Operations (1), (3), (1) in this order at appropriate positions, for example, to make $X$ change as `CCB` → `CAB` → `CBA` → `ABA` and coincide with $Y$."],["7\n5 ABABA BABAB\n5 ABCBC BBABA\n5 CCCCC CBABC\n5 BBAAA AAABB\n5 AAABB BBAAA\n5 ACACB BAACB\n5 ACACB BBACA","No\nYes\nYes\nNo\nYes\nYes\nNo"]],"created_at":"2026-03-03 11:01:14"}}