import pulp
import sys

def over_pocet(t, l, dlzky, pocty):
    n = len(dlzky)

    problem = pulp.LpProblem('Investicie', pulp.LpMaximize)
    kolko = [ [ pulp.LpVariable(f'odpil_{i}_{j}', cat='Integer') for j in range(t) ] for i in range(n) ]
    problem += t
    for i in range(n):
        for j in range(t):
            problem += kolko[i][j] >= 0
    for j in range(t):
        problem += sum( kolko[i][j] * dlzky[i] for i in range(n) ) <= l
    for i in range(n):
        problem += sum( kolko[i][j] for j in range(t) ) >= pocty[i]
    
    status = problem.solve(pulp.PULP_CBC_CMD(msg=0))
    if pulp.LpStatus[status] != 'Optimal':
        return False
    
    kolko = [ [ int(pulp.value(kolko[i][j])) for j in range(t) ] for i in range(n) ]
    print(t)
    print(t)
    for j in range(t):
        tyc = [ f'{kolko[i][j]}x{dlzky[i]}' for i in range(n) if kolko[i][j] ]
        print(1, *tyc)
    return True

def solve_one():
    l = int(input())
    n = int(input())
    dlzky = [ int(_) for _ in input().split() ]
    pocty = [ int(_) for _ in input().split() ]
    celkova_dlzka = sum( d*p for d,p in zip(dlzky, pocty) )
    t = (celkova_dlzka + l - 1) // l
    print(f'teoreticky lower bound: celkovy_pocet {sum(pocty)} celkova_dlzka {celkova_dlzka} min_t {t} leeway {l*t - celkova_dlzka} kratke {dlzky[:5]}', file=sys.stderr)
    sys.stderr.flush()
    while not over_pocet(t, l, dlzky, pocty): 
        print(f't = {t} failed', file=sys.stderr)
        sys.stderr.flush()
        t += 1

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