AtCoder Regular Contest 166
A
Replace C or Swap AB
AtCoder
⌀ 1126
原题
←B →
翻译中…

Problem Statement

翻译中…

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 on $X$ any number of times, possibly zero.

翻译中…
  • Operation (1):Choose a character C in $X$ and replace it with A.
  • Operation (2):Choose a character C in $X$ and replace it with B.
  • 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.
翻译中…

You have $T$ test cases to solve.

翻译中…

Constraints

翻译中…
  • $1\leq T\leq 2\times 10^5$
  • $1\leq N\leq 2\times 10^5$
  • Each of $X$ and $Y$ is a string of length $N$ consisting of A, B, and C.
  • The sum of $N$ over the test cases in a single input is at most $2\times 10^5$.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

T
\text{case}_1
\vdots
\text{case}_T

翻译中…

Each test case is given in the following format:

翻译中…

N X Y

翻译中…

Output

翻译中…

Print $T$ lines. The $i$-th line should contain Yes if it is possible to make $X$ coincide with $Y$ for the $i$-th test case, and No otherwise.

翻译中…

样例

Input #1
6
3 ABC ABC
1 C B
1 B C
2 AB BA
2 BA AB
3 CCB ABA
Output #1
Yes
Yes
No
Yes
No
Yes
- For the first test case, you can perform the operations zero times to make $X$ coincide with $Y$. - For the second test case, you can perform Operation (2) once to make $X$ coincide with $Y$. - For the fourth test case, you can perform Operation (3) once to make $X$ coincide with $Y$. - 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$.
Input #2
7
5 ABABA BABAB
5 ABCBC BBABA
5 CCCCC CBABC
5 BBAAA AAABB
5 AAABB BBAAA
5 ACACB BAACB
5 ACACB BBACA
Output #2
No
Yes
Yes
No
Yes
Yes
No
题目信息
题号
arc166_a
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。