Tricky Template (Codeforces 1922A)
Tags: Implement, strings

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".

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".

Sample Inputs:
4
1
a
b
c
2
aa
bb
aa
10
mathforces
luckforces
adhoccoder
3
acc
abd
abc

Sample Outputs:
YES
NO
YES
NO

Solution (Python):
t = int(input())
for i in range(t):
    n = int(input())
    a = input()
    b = input()
    c = input()
    poss = 'NO'
    for j in range(n):
        if a[j] != c[j] and b[j] != c[j]:
            poss = 'YES'
            break
    print(poss)

Solution (Python):
num = int(input())
ns = []
abcs = []
for z in range(num):
    ns.append(int(input()))
    abc = []
    for x in range(3):
        abc.append(input())
    abcs.append(abc)
for (abc, n) in zip(abcs, ns):
    ans = 'No'
    (a, b, c) = (abc[0], abc[1], abc[2])
    for (al, bl, cl) in zip(a, b, c):
        if cl == al or cl == bl:
            continue
        ans = 'Yes'
        break
    print(ans)

Solution (Python):
for i in range(int(input())):
    n = int(input())
    a = input()
    b = input()
    c = input()
    for i in range(n):
        if a[i] != c[i] and b[i] != c[i]:
            print('YES')
            break
    else:
        print('NO')