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