import math
from collections import deque
from sys import stdin, stdout
from string import ascii_letters
input = stdin.readline
#print = stdout.write
letters = ascii_letters[:26]

for _ in range(int(input())):
    n, m = map(int, input().split())
    first = set(map(int, input().split()))
    second = set(map(int, input().split()))
    res = list(first.intersection(second))
    if not len(res):
        print('NO')
    else:
        print('YES')
        print('1', res[0])
