t = int(input())

for _ in range(t):
    n,m = map(int,input().split())
    a = set(map(int,input().split()))
    b = set(map(int,input().split()))
    v = list(a & b)
    if v:
        print("YES")
        print(1,v[0])
    else:
        print("NO")