for _ in range(int(input())):
    n, m = map(int, input().split())
    a, b = set(list(map(int, input().split()))), set(list(map(int, input().split())))
    z = list(a.intersection(b))
    if z != []:
        print("YES\n1 {}".format(z[0]))
    else:
        print("NO")