t = int(input())
for _ in range(t):
    na, nb = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    a = set(a)
    b = set(b)
    c = list(a.intersection(b))
    if c!=[]:
        print('YES')
        print(1, c[0])
    else:
        print('NO')
