import random import time from math import exp def isvalid(tree): return e[tree[3]]maxi: maxi=now maxi_pos=cnt cnt+=1 return maxi-mini def score(trees): wa=0 use=[] for i in trees: use.append(high(i)) wa+=use[-1] ret=0 for i in use: ret+=((i*N)-wa)**2 return ret st=time.time() N,M=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) c=list(map(int,input().split())) d=list(map(int,input().split())) e=list(map(int,input().split())) f=list(map(int,input().split())) tip=list(zip(a,b,range(N))) center=list(zip(c,d,range(N*2))) stem=list(zip(e,f,range(N))) tip.sort(reverse=True) center.sort(reverse=True) stem.sort(reverse=True) tip_stock=set(range(N)) center_stock=set(range(N*2)) stem_stock=set(range(N)) tree=[] for i in range(M): while stem[-1][0]>=tip[-1][0]: tip.pop() while tip[-1][0]>=center[-1][0]: center.pop() tree.append([tip[-1][2],center[-1][2],center[-2][2],stem[-1][2]]) tip_stock.discard(tip[-1][2]) center_stock.discard(center[-1][2]) center_stock.discard(center[-2][2]) stem_stock.discard(stem[-1][2]) center.pop() center.pop() tip.pop() stem.pop() tip_stock=list(tip_stock) center_stock=list(center_stock) stem_stock=list(stem_stock) mini_pos=-1 maxi_pos=-1 now=row_score(tree) t_st=50000 t_gl=1 count=0 best=now fin=[i[:] for i in tree] while time.time()-st<1.1: count+=1 now_temp=t_st*(t_gl/t_st)**((time.time()-st)*0.90909) befmi=mini_pos befma=maxi_pos if random.random()<0.7: if random.random()<0.5: lf=mini_pos else: lf=maxi_pos ri=random.randint(0,M-1) if lf==ri: ri=(ri+1)%M if random.random()<0.25: tree[lf][0],tree[ri][0]=tree[ri][0],tree[lf][0] if not(isvalid(tree[lf]) and isvalid(tree[ri])): tree[lf][0],tree[ri][0]=tree[ri][0],tree[lf][0] else: sc=row_score(tree) if not(scnow: fin=[i[:] for i in tree] best=now for i in fin: print(*(map(lambda x:x+1,i)))