def ans():
    set_a = set(a)
    set_b  = set(b)
    if (set_a&set_b):
        print("YES")
        f = list(set_a&set_b)
        print(1,f[0])
    else:
        print("NO")
    
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()))
    ans()