import collections
for _ in range(int(input())):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    aa=set(a)
    bb=set(b)
    flag=False
    for val in list(set(a+b)):
        if val in a and val in b:
            print('YES')
            print(1,val)
            flag=True
            break
    if not flag:
        print("NO")
        