for i in range(int(input())):
    n, m = map(int, input().split())
    set_n = set(map(int, input().split()))
    set_m = set(map(int, input().split()))
    intersection = set_n & set_m
    if intersection != set():
        print('YES')
        for j in intersection:
            answer = j
            break
        print(1, answer)
    else:
        print('NO')