311019: CF1922A. Tricky Template

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A. Tricky Templatetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

You are given an integer $n$ and three strings $a, b, c$, each consisting of $n$ lowercase Latin letters.

Let a template be a string $t$ consisting of $n$ lowercase and/or uppercase Latin letters. The string $s$ matches the template $t$ if the following conditions hold for all $i$ from $1$ to $n$:

  • if the $i$-th letter of the template is lowercase, then $s_i$ must be the same as $t_i$;
  • if the $i$-th letter of the template is uppercase, then $s_i$ must be different from the lowercase version of $t_i$. For example, if there is a letter 'A' in the template, you cannot use the letter 'a' in the corresponding position of the string.

Accordingly, the string doesn't match the template if the condition doesn't hold for at least one $i$.

Determine whether there exists a template $t$ such that the strings $a$ and $b$ match it, while the string $c$ does not.

Input

The first line contains an integer $t$ ($1 \le t \le 1000$) — the number of test cases.

The first line of each test case contains an integer $n$ ($1 \le n \le 20$) — the length of the given strings.

The next three lines contain the strings $a, b$ and $c$. Each string consists of exactly $n$ lowercase Latin letters.

Output

For each testcase, print "YES" if there exists a template $t$ such that the strings $a$ and $b$ match it, while the string $c$ does not. Otherwise, print "NO".

ExampleInput
4
1
a
b
c
2
aa
bb
aa
10
mathforces
luckforces
adhoccoder
3
acc
abd
abc
Output
YES
NO
YES
NO
Note

In the first test case, you can use the template "C". The first letter of strings $a$ and $b$ differ from 'c', so they match the template. The first letter of string $c$ equals 'c', so it doesn't match.

In the third test case, you can use the template "CODEforces".

Output

题目大意:
给定一个整数n和三个由n个小写拉丁字母组成的字符串a、b、c。一个模板t是由n个小写或大写拉丁字母组成的字符串。如果对于所有1到n的i,以下条件成立,则字符串s与模板t匹配:

- 如果模板的第i个字母是小写,那么s_i必须与t_i相同;
- 如果模板的第i个字母是大写,那么s_i必须与t_i的小写版本不同。

根据这个定义,如果至少有一个i不满足条件,则字符串不匹配模板。

确定是否存在一个模板t,使得字符串a和b匹配它,而字符串c不匹配。

输入输出数据格式:
输入:
第一行包含一个整数t(1≤t≤1000)——测试用例的数量。
每个测试用例的第一行包含一个整数n(1≤n≤20)——给定字符串的长度。
接下来的三行包含字符串a、b和c。每个字符串恰好由n个小写拉丁字母组成。

输出:
对于每个测试用例,如果存在一个模板t,使得字符串a和b匹配它,而字符串c不匹配,则打印“YES”。否则,打印“NO”。

示例输入输出:
输入:
```
4
1
a
b
c
2
aa
bb
aa
10
mathforces
luckforces
adhoccoder
3
acc
abd
abc
```
输出:
```
YES
NO
YES
NO
```

注意:
在第一个测试用例中,可以使用模板"C"。字符串a和b的第一个字母与'c'不同,所以它们匹配模板。字符串c的第一个字母等于'c',所以它不匹配。
在第三个测试用例中,可以使用模板"CODEforces"。题目大意: 给定一个整数n和三个由n个小写拉丁字母组成的字符串a、b、c。一个模板t是由n个小写或大写拉丁字母组成的字符串。如果对于所有1到n的i,以下条件成立,则字符串s与模板t匹配: - 如果模板的第i个字母是小写,那么s_i必须与t_i相同; - 如果模板的第i个字母是大写,那么s_i必须与t_i的小写版本不同。 根据这个定义,如果至少有一个i不满足条件,则字符串不匹配模板。 确定是否存在一个模板t,使得字符串a和b匹配它,而字符串c不匹配。 输入输出数据格式: 输入: 第一行包含一个整数t(1≤t≤1000)——测试用例的数量。 每个测试用例的第一行包含一个整数n(1≤n≤20)——给定字符串的长度。 接下来的三行包含字符串a、b和c。每个字符串恰好由n个小写拉丁字母组成。 输出: 对于每个测试用例,如果存在一个模板t,使得字符串a和b匹配它,而字符串c不匹配,则打印“YES”。否则,打印“NO”。 示例输入输出: 输入: ``` 4 1 a b c 2 aa bb aa 10 mathforces luckforces adhoccoder 3 acc abd abc ``` 输出: ``` YES NO YES NO ``` 注意: 在第一个测试用例中,可以使用模板"C"。字符串a和b的第一个字母与'c'不同,所以它们匹配模板。字符串c的第一个字母等于'c',所以它不匹配。 在第三个测试用例中,可以使用模板"CODEforces"。

加入题单

上一题 下一题 算法标签: