该题40%, 交卷18分,怀疑人生。
import sys
if __name__ == '__main__':
n = int(sys.stdin.readline().strip())
for _ in range(n):
strs = []
flag = False
m = int(sys.stdin.readline().strip())
for i in range(m):
line = sys.stdin.readline().strip()
strs.append(line)
for i in range(len(strs)-1):
for j in range(i+1, len(strs)):
str1 = strs[i]
str2 = strs[j]
for k in range(len(str2)):
if str1[0] == str2[k]:
str3 = str2[k:] + str2[:k]
str41 = str2[:k+1]
str42 = str2[k+1:]
str4 = str41[::-1] + str42[::-1]
if str1 == str3 or str1 == str4:
flag = True
if flag:
print('Yeah')
else:
print('Sad')