t = int(input())
while t:
    t += -1
    n, m = map(int, input().split())
    l1 = list(map(int, input().split()))
    l2 = list(map(int, input().split()))
    ans = 0
    for i in l1:
        if i in l2: 
            ans = i
            break
    if ans:
        print('YES')
        print(1, ans)
    else: print('NO')