from collections import defaultdict
for _ in range(int(input())):
    n, m = list(map(int, input().split()))
    arr = list(map(int, input().split()))
    brr = list(map(int, input().split()))
    d = defaultdict(int)
    for i in brr:
        d[i] = 1
    x = -1
    for i in arr:
        if d[i] == 1:
            x = i
    if x == -1:
        print("NO")
    else:
        print("YES")
        print(1, x)
