import pulp

def over_dve(l, tyce):
    n = len(tyce)
    celkova_dlzka = sum(tyce)

    problem = pulp.LpProblem('Tyce', pulp.LpMaximize)
    na_prvu = [ pulp.LpVariable(f'na_prvu_{i}', cat='Binary') for i in range(n) ]

    problem += 2
    problem += sum( na_prvu[i] * tyce[i] for i in range(n) ) <= l
    problem += sum( na_prvu[i] * tyce[i] for i in range(n) ) >= celkova_dlzka-l

    status = problem.solve(pulp.PULP_CBC_CMD(msg=0))
    assert pulp.LpStatus[status] == 'Optimal'

    print(2)
    print(2)
    na_prvu = [ int(pulp.value(na_prvu[i])) for i in range(n) ]
    print(1, *[ tyce[i] for i in range(n) if na_prvu[i] ] )
    print(1, *[ tyce[i] for i in range(n) if not na_prvu[i] ] )

def solve_one():
    l = int(input())
    n = int(input())
    dlzky = [ int(_) for _ in input().split() ]
    pocty = [ int(_) for _ in input().split() ]
    tyce = []
    for d, p in zip(dlzky, pocty): tyce += [d]*p
    if sum(tyce) <= l:
        print(1)
        print(1)
        print(1, *tyce)
    else:
        over_dve(l, tyce)

tc = int( input() )
for test in range(tc): solve_one()
