import sys
import math
from collections import defaultdict as dd
mod=1000000007
T=1
T=int(sys.stdin.readline())
for _ in range(T):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    flg=1
    p=-1
    for i in a:
        if i in b:
            flg=0
            p=i
            break
    if flg:
        print('NO')
    else:
        print('YES')
        print(1,p)
