def solve():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    for val in a:
        if val in b:
            print ('YES')
            print (1, val)
            return
    print ('NO')

t = int(input())
for _ in range(t):
    solve()
    