for _  in range(int(input())):
    n,m = map(int,input().split())
    a = set(map(int,input().split()))
    b = set(map(int,input().split()))
    fl = 0
    ans  =  0
    for i in a:
        if i in b:
            fl=1
            ans =  i
            break
    if fl: 
        print("YES")
        print(1,ans)
    else:
        print("NO")
