import math

for i in range(int(input())):
    n, m = map(int, input().split())
    a = [int(j) for j in input().split()]
    b = [int(j) for j in input().split()]
    a = list(set(a))
    b = list(set(b))
    a.sort()
    b.sort()
    z = 0
    for j in range(len(a)):
        if a[j] in b:
            print('YES')
            z = 1
            print(1, a[j])
            break
    if z == 0:
        print('NO')