# https://codeforces.com/problemset/problem/1382/A

t = int(input())
for _ in range(t):
    n, m = [int(x) for x in input().split()]
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
    
    answ = None # current answer
    for elem in a:
        if elem in b:
            answ = elem
            break
    if answ == None:
        print('NO')
    else:
        print('YES')
        print(f'1 {elem}')