for _ in range(int(input())):
    n, m = list(map(int, input().split()))
    a = set(list(map(int, input().split())))
    b = set(list(map(int, input().split())))
    c = a & b
    if len(c) != 0:
        print('YES')
        for elem in c:
            print(1, elem)
            break
    else:
        print('NO')
