import sys


def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_list(): return set(map(int, sys.stdin.readline().strip().split()))


t = int(input())
for x in range(t):
    n, m = get_ints()
    a = get_list()
    b = get_list()
    inter = a.intersection(b)
    if len(inter) > 0:
        print("YES")
        print("1 %d" % inter.pop())
    else:
        print("NO")
