#!/usr/bin/pypy3
for _ in range(int(input())):
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    f = True
    for i in a:
        if i in b:
            print('YES')
            print(1, i)
            f = False
            break
    if f is True:
        print('NO')
