t=int(input())
for i in range(t):
    n, m=map(int, input().split())
    A=list(map(int, input().split()))
    B=list(map(int, input().split()))
    k=0
    for i in A:
        if i in B:
            k=1
            print('YES')
            print(1, i)
            break
    if k==0:
        print('NO')