t = int(input())
for _ in range(t):
    n, m = map(int,input().split())
    arr1 = list(map(int,input().split()))
    arr2 = list(map(int,input().split()))
    
    for i in range(n):
        if arr1[i] in arr2:
            print("YES")
            print(1, arr1[i])
            break
    else:
        print("NO")