def solve():

    n , m = map(int,input().split())
    lst1 = list(map(int,input().split()))
    lst2 = list(map(int,input().split()))

    for i in range(n):
        if(lst1[i] in lst2):
            print("YES")
            print(1 , lst1[i])
            return
    print("NO")
    
t = int(input())

for i in range(t):
    solve()
