# Don't ever let good enough be good enough. Bill Parcells
# by : Blue Edge - Create some chaos

for _ in range(int(input())):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    c=[0]*1001
    d=[0]*1001
    for x in a:
        c[x]=1
    for x in b:
        d[x]=1

    for i in range(1000+1):
        if c[i]&d[i]:
            print("YES")
            print(1,i)
            break
    else:
        print("NO")
