import itertools
import gurobipy as gp
from gurobipy import GRB
import sys

def over_pocet(t, l, dlzky, pocty):
    n = len(dlzky)
    env = gp.Env(empty=True)
    env.setParam('OutputFlag', 0)
    env.start()
    model = gp.Model('tyce_knapsack', env=env)
    model.setParam('MIPGap', 0.0)
    model.setParam('IntegralityFocus', 1)
    model.setParam('IntFeasTol', 1e-9)
    rod_vars = model.addVars(t, n, vtype=GRB.INTEGER, name='rod')
        
    model.addConstrs((rod_vars[j, i] >= 0 for j in range(t) for i in range(n)))
    model.addConstrs((rod_vars.sum('*', i) >= pocty[i] for i in range(n)))
    for j in range(t):
        model.addConstr( gp.quicksum( rod_vars[j, i] * dlzky[i] for i in range(n) ) <= l )

    model.optimize()
    if model.status != GRB.OPTIMAL: return False
    solution = model.getAttr('Xn', rod_vars)
    kolko = [ [ int(round(solution[j,i])) for i in range(n) ] for j in range(t) ]

    print(t)
    print(t)
    for j in range(t):
        tyc = [ f'{kolko[j][i]}x{dlzky[i]}' for i in range(n) if kolko[j][i] ]
        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

if __name__ == '__main__':
    tc = int( input() )
    for test in range(tc): solve_one()

