t = int(input())

for _ in range(t):
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    for i in range(len(a)):
        if(a[i] in b):
            print("YES")
            print(1, a[i])
            break
        elif(i == len(a)-1):
            print("NO")
