import sys readline=sys.stdin.readline write=sys.stdout.write N=int(readline()) for n in range(N): lst0=list(map(int,readline().split())) lst1=list(map(int,readline().split())) X=readline().rstrip() i=['AC', 'WA', 'TLE', 'MLE', 'OLE', 'RE'].index(X) if lst0[i]==0 and all(lst1[j]==0 for j in range(1,6) if i!=j): ans="Yes" else: ans="No" print(ans)