# cook your dish here
for _ in range (int(input())):
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    f = 0
    for i in range (n):
        if a[i] in b:
            f = 1
            p = a[i]
            break
    if f:
        print("YES")
        print(1, p)
    else:
        print("NO")