t = int(input())
for i in range(t):
    n, m = map(int, input().split())
    a = set(map(int, input().split()))
    b = set(map(int, input().split()))
    c = a.intersection(b)
    if(len(c)):
        print("YES")
        cnt = 0
        print(1, end = " ")
        for j in a:
            if(j in b):
                print(j, end = " ")
                print()
                break
    else:
        print("NO")