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

You are given three strings a a , b b and c c of the same length n n . The strings consist of lowercase English letters only. The i i -th letter of a a is a i a_i , the i i -th letter of b b is b i b_i , the i i -th letter of c c is c i c_i .

For every i i ( 1 i n 1 \leq i \leq n ) you must swap (i.e. exchange) c i c_i with either a i a_i or b i b_i . So in total you’ll perform exactly n n swap operations, each of them either c i a i c_i \leftrightarrow a_i or c i b i c_i \leftrightarrow b_i ( i i iterates over all integers between 1 1 and n n , inclusive).

For example, if a a is “code”, b b is “true”, and c c is “help”, you can make c c equal to “crue” taking the 1 1 -st and the 4 4 -th letters from a a and the others from b b . In this way a a becomes “hodp” and b b becomes “tele”.

Is it possible that after these swaps the string a a becomes exactly the same as the string b b ?

Input

The input consists of multiple test cases. The first line contains a single integer t t ( 1 t 100 1 \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 a a .

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

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

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

Output

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

If it is possible to make string a a equal to string b b 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 a a becomes exactly the same as string b b .

In the second test case, you should swap c i c_i with a i a_i for all possible i i . After the swaps a a becomes “bca”, b b becomes “bca” and c c becomes “abc”. Here the strings a a and b b are equal.

In the third test case, you should swap c 1 c_1 with a 1 a_1 , c 2 c_2 with b 2 b_2 , c 3 c_3 with b 3 b_3 and c 4 c_4 with a 4 a_4 . Then string a a becomes “baba”, string b b becomes “baba” and string c c becomes “abab”. Here the strings a a and b b are equal.

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

Process

Compare c i c_i and a i a_i , if a i a_i and c i c_i are equal, we need to swap c i c_i with b i b_i to make a i a_i and b i b_i are equal. If the comparision shows that a i a_i and c i c_i are not equal, please compare c i c_i and b i b_i . If c i c_i and b i b_i are equal, we should swap c i c_i and a i a_i . As i i increases, keep comparing c i c_i and b i b_i or a i a_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;
    }
发布了228 篇原创文章 · 获赞 30 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_43510916/article/details/104313287