t = int(input())
for _ in range (t):
    N,M = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = []
    for i in B:
        if i in A:
            C.append(i)
            break
    if C == []:
        print('NO')
    else:
        print('YES')
        print(1, C[0])
    