t = int(input())
for i in range(t):
    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    f = 0
    for j in a:
        if j in b:
            print("YES")
            print("1"+" " +str(j))
            f = 1
            break
    if f==0:
        print("NO")        
        
    