import sys
input = sys.stdin.readline

N = int(input())

for _ in range(N):
    l = list(map(int, input().split()))
    l2 = list(map(int, input().split()))
    X = input()[:-1]
    
    if X=='WA':
        mark = 1
    elif X=='TLE':
        mark = 2
    elif X=='MLE':
        mark = 3
    elif X=='OLE':
        mark = 4
    else:
        mark = 5
    
    if l[mark]!=0:
        print('No')
        continue
    
    for i in range(1, 6):
        if i!=mark and l2[i]!=0:
            print('No')
            break
    else:
        print('Yes')