t=int(input())
for _ in range(t):
    n,x=input().split()
    a,b=list(map(int,input().split())),list(map(int,input().split()))
    try:
        check=[i for i in a if i in b]
        print('YES\n'+'1',check[0])
    except: print('NO')