#https://codeforces.com/contest/1382/problem/0
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
# do magic here
t = int(input())
for _ in range(t):
    n,m = map(int,input().split())
    arr1 = set(list(map(int,input().split())))
    arr2 = set(list(map(int,input().split())))
    ok = "NO"
    for x in arr1:
        if x in arr2:
            ok  = x
            break
    if ok=="NO":
        print(ok)
    else:
        print("YES")
        print(1,ok)