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