import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class VincentFast {
	private static void read() throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] line = br.readLine().split(" ");
		int K = Integer.parseInt(line[0]);
		int N = Integer.parseInt(line[1]);
		int[][] output = new int[3][N];
		line = br.readLine().split(" ");
		List<Integer> A = Arrays.stream(line).map(Integer::parseInt).toList();
		line = br.readLine().split(" ");
		List<Integer> B = Arrays.stream(line).map(Integer::parseInt).toList();
		br.close();
		@SuppressWarnings("unchecked")
		List<Integer>[][] pieces = new List[4][4];
		for (int a = 1; a <= 3; a++) {
			for (int b = a; b <= 3; b++) {
				pieces[a][b] = new ArrayList<>();
			}
		}
		for (int i = 0; i < K; i++) {
			pieces[A.get(i)][B.get(i)].add(i + 1);
		}
		
		/**
		 * Je place bourrinement les 2x2, puis les 2x3 (verticalement), puis les 3x3. 
		 */
		
		int x = 0;
		for (int i = 2; i <= 3; i++) {
			for (int j = i; j <= 3; j++) {
				for (int k : pieces[i][j]) {
					for (int u = 0; u < j; u++) {
						for (int v = 0; v < i; v++) {
							output[u][x + v] = k;
						}
					}
					x += i;
				}
			}
		}
		/**
		 * Stratégie : Je mets toutes mes pièces 1x2, puis 1x3, puis 1x1, jusqu'à
		 * couvrir ou dépasser une longueur 2sq. Si je dépasse de d = 1 ou d = 2, - j'ai
		 * utilisé tous mes 1x2, au moins un 1x3, et aucun 1x1 ; - je n'ai plus de 1x2
		 * en réserve ; - j'ai au moins (3 - d) 1x1 en réserve, car il me reste une aire
		 * 3-d mod 3 à paver.
		 * 
		 * Si je dépasse de 2, je remplace un 1x3 par un 1x1. Si je dépasse de 1, je
		 * remplace un 1x3 par deux 1x1.
		 * 
		 * Algo auxiliaire équivalent : je mets des 1x2 puis 1x3 puis 1x1 de manière
		 * gloutonne, sans dépasser la longueur 2sq.
		 */
		int sq = pieces[2][2].size();
		int a1 = pieces[1][1].size();
		int a2 = pieces[1][2].size();
		int a3 = pieces[1][3].size();
		int b1 = 0;
		int b2 = 0;
		int b3 = 0;
		int xx = 0;
		while (xx < 2 * sq) {
			if (b2 < a2) {
				output[2][xx] = pieces[1][2].get(b2);
				output[2][xx + 1] = pieces[1][2].get(b2);
				b2++;
				xx += 2;
			} else if (b3 < a3 && xx + 3 <= 2 * sq) {
				output[2][xx] = pieces[1][3].get(b3);
				output[2][xx + 1] = pieces[1][3].get(b3);
				output[2][xx + 2] = pieces[1][3].get(b3);
				b3++;
				xx += 3;
			} else if (xx < 2 * sq) {
				output[2][xx] = pieces[1][1].get(b1);
				b1++;
				xx++;
			}
		}
		
		/**
		 * Je finis de placer les 1x? résiduels.
		 */
		for (; b3 < a3; b3++) {
			output[0][x] = pieces[1][3].get(b3);
			output[1][x] = pieces[1][3].get(b3);
			output[2][x] = pieces[1][3].get(b3);
			x++;
		}
		for (; b2 + 3 <= a2; b2 += 3) {
			output[0][x] = pieces[1][2].get(b2);
			output[0][x + 1] = pieces[1][2].get(b2);
			output[1][x] = pieces[1][2].get(b2 + 1);
			output[1][x + 1] = pieces[1][2].get(b2 + 1);
			output[2][x] = pieces[1][2].get(b2 + 2);
			output[2][x + 1] = pieces[1][2].get(b2 + 2);
			x += 2;
		}
		for (; b1 + 3 <= a1; b1 += 3) {
			output[0][x] = pieces[1][1].get(b1);
			output[1][x] = pieces[1][1].get(b1 + 1);
			output[2][x] = pieces[1][1].get(b1 + 2);
			x++;
		}
		for (; b2 < a2; b2++) {
			output[0][x] = pieces[1][2].get(b2);
			output[1][x] = pieces[1][2].get(b2);
			output[2][x] = pieces[1][1].get(b1);
			b1++;
			x++;
		}
		
		/**
		 * J'imprime le tout.
		 */
		for (int i = 0; i < 3; i++) {
			System.out.println(Arrays.stream(output[i]).mapToObj(Integer::toString).collect(Collectors.joining(" ")));
		}
	}

	public static void main(String[] args) throws IOException {
		read();
	}
}

