from sys import stdin

rints = lambda: [int(x) for x in stdin.readline().split()]
for _ in range(int(input())):
    n, m = rints()
    a, b = rints(), rints()
    dis = set(a).intersection(b)
    if dis:
        print('%s\n%d %d' % ('YES', 1, dis.pop()))
    else:
        print('NO')
