import sys
input = sys.stdin.readline

for _ in range(int(input())):
    n, m = map(int, input().split())
    a = set([int(i) for i in input().split()])
    b = set([int(i) for i in input().split()])
    if a & b:
        print("YES")
        print(1, list(a & b)[0])
    else:
        print("NO")
