from collections import defaultdict
t = int(input())
while t:
    t-=1
    n,m = [int(i) for i in input().split()]
    l1 = [int(i) for i in input().split()]
    l2 = [int(i) for i in input().split()]
    flag = 0
    num = 0
    for i in l2:
        if i in l1:
           num = i
           flag = 1
           break
    if flag == 1:
        print("YES")
        print("{} {}".format(1,i))
    else:
        print("NO")