from collections import Counter
t = int(input())
for _ in range(t):
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    d = {}
    for i in a:
        d[i] = 1
    for i in b:
        if d.get(i, -1) == 1:
            print('YES')
            print(1,i)
            break
    else:
        print("NO")
