t=int(input())
for i in range(t):
    n,m = map(int, input().split())
    a=list(int(num) for num in input().split())
    b=list(int(num) for num in input().split())
    na=[x for x in a if x in b]
    if na:
        print("YES")
        print("1",na[0])
    else:
        print("NO")
