
for _ in range(int(input())):
    n,m = list(map(int, input().split()))
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    arra = [0]*1001
    arrb = [0]*1001
    for i in range(len(a)):
        arra[a[i]]+=1
    for i in range(len(b)):
        arrb[b[i]]+=1
    u = 0
    for i in range(1001):
        if(arra[i]!=0 and arrb[i]!=0):
            print("YES")
            print(1, i)
            u = 1
            break
    if(u == 0):
        print("NO")