import math
import sys
from collections import Counter
T = int(input())
for _ in range(0,T):
    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    x = list(set(a).intersection(set(b)))
    if len(x) == 0:
        print("NO")
    else:
        print("YES")
        print(1,x[0])