t = int(input())
for it in range(t):
    n, m = list(map(int, input().split()))
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    k = True
    for i in range(n):
        if a[i] in b:
            k = False
            print("YES")
            print(1, a[i])
            break
    if k:
        print("NO")

