import sys
input=sys.stdin.readline
t=int(input())
for tt in range(t):
    n,m=map(int,input().split())
    l1 = list(map(int,input().split()))
    l2 = list(map(int,input().split()))
    d = {}
    for i in l1:
        d[i] = 0
    for i in l2:
        try:
            d[i]+=1
        except:
            pass
    ans = -1
    for i in d:
        if d[i] > 0:
            ans = i
            break
    if ans == -1:
        print("NO")
    else:
        print("YES")
        print(1,ans)
    