t = int(input())
for _ in range(t):
    n, m = map(int, input().split())
    a = set(map(int, input().split()))
    b = map(int, input().split())
    res = -1
    for i in b:
        if i in a:
            res = i
            break
    if res < 0:
        print("NO")
    else:
        print("YES")
        print(1, res)
