import sys
input = sys.stdin.readline
from collections import *

for _ in range(int(input())):
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    sa = set(a)
    sb = set(b)
    
    if len(sa&sb)>=1:
        print('YES')
        print(1, list(sa&sb)[0])
    else:
        print('NO')