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()))
    x=set(a)
    tf=True
    for i in b:
        if i in x:
            print('YES')
            print(1,i)
            tf=False
            break
    if tf:
        print('NO')