def commonSeq(a,b):
    for i in a:
        for j in b:
            if i == j:
                print('YES')
                print(str(1)+' '+str(i))
                return
    print('NO')
    return

for i in range(int(input())):
    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    commonSeq(a,b)
