
T = int(input())
for t in range(T):
    n, m = map(int, input().split())
    a = set(map(int, input().split()))
    b = set(map(int, input().split()))
    ret = None
    if n < m:
        for key in a:
            if key in b:
                ret = key
                break
    else:
        for key in b:
            if key in a:
                ret = key
                break
    if ret != None:
        print(f"YES\n{1} {ret}")
    else:
        print("NO")