t = int(input())

for i in range(t):
    ans = ""
    n,m = map(int,input().split())
    l1 = list(map(int,input().split()))
    l2 = list(map(int,input().split()))
    
    for j in l1:
        if j in l2:
            ans = j
            break
    
    if ans:
        print("YES")
        print(1,ans)
    else:
        print("NO")
        