from collections import defaultdict

test_case_count = int(input())
for i in range(test_case_count):
    arr_lens = input().split(" ")
    arr1 = input().split(" ")
    arr2 = input().split(" ")
    d = defaultdict(bool)
    for item in arr1:
        d[item] = True
    length = 0
    for item in arr2:
        if item in d.keys():
            length = 1
            scs = item
    if length:
        print("YES\n1 ",scs)
    else:
        print("NO")