from sys import stdin
for _ in range(int(stdin.readline())):
    n,m = map(int,stdin.readline().split())
    a = set(map(int,stdin.readline().split()))
    b = set(map(int,stdin.readline().split()))
    x = a.intersection(b)
    if len(x):
        print('YES')
        print(1,x.pop())
    else:
        print('NO')
