import pulp
import sys

def to_int(x): return int(round(x))

def solve_one():
    l = int(input())
    n = int(input())
    dlzky = [ int(_) for _ in input().split() ]
    pocty = [ int(_) for _ in input().split() ]

    patterns = set( [ tuple() ] )
    for d in dlzky:
        new_patterns = set()
        for pat in patterns:
            new_patterns.add(pat)
            pat = list(pat)
            while True:
                pat.append(d)
                if sum(pat) > l: break
                if pat.count(d) > pocty[ dlzky.index(d) ]: break
                new_patterns.add( tuple(pat) )
        patterns = new_patterns
        print(f'after {d}: {len(patterns)} patterns', file=sys.stderr)

    patterns = list(patterns)
    patterns = [ [ pat.count(d) for d in dlzky ] for pat in patterns ]
    p = len(patterns)
    print(f'final count: {p} patterns', file=sys.stderr)

    celkova_dlzka = sum( d*p for d,p in zip(dlzky, pocty) )
    t = (celkova_dlzka + l - 1) // l
    print(f'celkova_dlzka {celkova_dlzka} lower bound t {t}', file=sys.stderr)

    problem = pulp.LpProblem('Tyce', pulp.LpMinimize)
    kolko = [ pulp.LpVariable(f'kusov_{i}', cat='Binary') for i in range(p) ]
    problem += pulp.lpSum( kolko[i] for i in range(p) )
    for i in range(p):
        problem += kolko[i] >= 0
    for j in range(n):
        problem += pulp.lpSum( kolko[i] * patterns[i][j] for i in range(p) if patterns[i][j] ) >= pocty[j]

    status = problem.solve(pulp.PULP_CBC_CMD(msg=0))
    assert pulp.LpStatus[status] == 'Optimal'
    t = to_int( pulp.value( problem.objective ) )
    print(t)
    print(t)
    for i in range(p):
        cnt = to_int( pulp.value( kolko[i] ) )
        if cnt == 0: continue
        rob = [ dlzky[j] for j in range(n) if patterns[i][j] ]
        print(1, *rob)

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