def solve(a, b):
    for i in a:
        if i in b:
            print("YES")
            print("1", i)
            break
    else:
        print("NO")
    
    #return
# sys.stdin = open('input.txt', "r")
# sys.stdout = open('output.txt', 'w')
t = int(input())
for _ in range(t):
    n, m = map(int, input().split())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
    solve(a, b)
