Codeforces Round #619 (Div. 2)_A. Three Strings(C++_模拟)

删除回忆录丶 提交于 2020-02-16 10:04:27

You are given three strings aa, bb and cc of the same length nn. The strings consist of lowercase English letters only. The ii-th letter of aa is aia_i, the ii-th letter of bb is bib_i, the ii-th letter of cc is cic_i.

For every ii (1in1 \leq i \leq n) you must swap (i.e. exchange) cic_i with either aia_i or bib_i. So in total you’ll perform exactly nn swap operations, each of them either ciaic_i \leftrightarrow a_i or cibic_i \leftrightarrow b_i (ii iterates over all integers between 11 and nn, inclusive).

For example, if aa is “code”, bb is “true”, and cc is “help”, you can make cc equal to “crue” taking the 11-st and the 44-th letters from aa and the others from bb. In this way aa becomes “hodp” and bb becomes “tele”.

Is it possible that after these swaps the string aa becomes exactly the same as the string bb?

Input

The input consists of multiple test cases. The first line contains a single integer tt (1t1001 \leq t \leq 100) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a string of lowercase English letters aa.

The second line of each test case contains a string of lowercase English letters bb.

The third line of each test case contains a string of lowercase English letters cc.

It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding 100100.

Output

Print tt lines with answers for all test cases. For each test case:

If it is possible to make string aa equal to string bb print “YES” (without quotes), otherwise print “NO” (without quotes).

You can print either lowercase or uppercase letters in the answers.

Example

Input

4
aaa
bbb
ccc
abc
bca
bca
aabb
bbaa
baba
imi
mii
iim

Output

NO
YES
YES
NO

Note

In the first test case, it is impossible to do the swaps so that string aa becomes exactly the same as string bb.

In the second test case, you should swap cic_i with aia_i for all possible ii. After the swaps aa becomes “bca”, bb becomes “bca” and cc becomes “abc”. Here the strings aa and bb are equal.

In the third test case, you should swap c1c_1 with a1a_1, c2c_2 with b2b_2, c3c_3 with b3b_3 and c4c_4 with a4a_4. Then string aa becomes “baba”, string bb becomes “baba” and string cc becomes “abab”. Here the strings aa and bb are equal.

In the fourth test case, it is impossible to do the swaps so that string aa becomes exactly the same as string bb.

Process

Compare cic_i and aia_i , if aia_i and cic_i are equal, we need to swap cic_i with bib_i to make aia_i and bib_i are equal. If the comparision shows that aia_i and cic_i are not equal, please compare cic_i and bib_i. If cic_i and bib_i are equal, we should swap cic_i and aia_i. As ii increases, keep comparing cic_i and bib_i or aia_i until they are not equal.

Code

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
    	int n;
    	cin >> n;
    	for (int j = 1; j <= n; j++)
    	{
    		bool flag = 1;
    		string a, b, c;
    		cin >> a >> b >> c;
    		for (int i = 0; i < a.size(); i++)
    		{
    			char temp;
    			if (c[i] == a[i])
    			{
    				temp = c[i];
    				c[i] = b[i];
    				b[i] = temp;
    			}
    			else if (c[i] == b[i])
    			{
    				temp = c[i];
    				c[i] = a[i];
    				a[i] = temp;
    			}
    			else
    			{
    				flag = 0;
    				break;
    			}
    		}
    		if (flag)
    			cout << "YES" << endl;
    		else
    			cout << "NO" << endl;
    	}
    	return 0;
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!