t = int(input())
while(t>0):
    t = t-1
    n,m = map(int,input().split())
    a = input()
    A = list(map(int,list(a.split())))
    b = input()
    B = list(map(int,list(b.split())))
    d = {}
    e = {}
    flag = 0
    for i in A:
        d[i] = 1
    for i in B:
        e[i] = 1
    for i in d:
        if i in e:
            flag = 1
            break
    if flag == 0:
        print("NO")
    else:
        print("YES")
        print(1,end=" ")
        print(i)