def func(c, b):
    for i in b:
        if c[i] != 0:
            print('YES')
            print(1,i)
            return
    print('NO')
    return
    

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()))
    c = Counter(a)
    func(c,b)