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()))

    result = set(a) & set(b)
    if len(result)>0:
        print("YES")
        print(1,min(result))
    else:
        print("NO")