ll = lambda: list(map(int, input().split()))
st= lambda: input()
v = lambda: map(int, input().split())
ii = lambda: int(input())
from collections import *
from math import *
from datetime import datetime
from sys import stdin, stdout
for h in range(int(input())):
    n,m=v()
    l=set(ll())
    y=set(ll())
    ans=list(l&y)
    if(ans):
        print("YES")
        print(1,ans[0])
    else:
        print("NO")