t = int(input())
for i in range(t):
    n,m = list(map(int,input().split()))
    vetor1 = list(map(int,input().split()))
    vetor2 = list(map(int,input().split()))
    flag = False
    for a in range(n):
        if(vetor1[a] in vetor2):
            flag = True
            break
    if flag:
        print("YES")
        print(1,vetor1[a])
    else:
        print("NO")
