def solve():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    
    for i in a:
        for j in b:
            if i == j:
                print("YES")
                print("1", i)
                return
    print("NO")
    
for t in range(int(input())):
    solve()
    
    
