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.StringJoiner;
import java.util.stream.Collectors;

public class VincentFast2 {
	private static void read() throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] KN = br.readLine().split(" ");
		String[] A = br.readLine().split(" ");
		String[] B = br.readLine().split(" ");
		br.close();
		int K = Integer.parseInt(KN[0]);
		int N = Integer.parseInt(KN[1]);
		int[][] output = new int[3][N];
		@SuppressWarnings("unchecked")
		int[][][] pieces = new int[4][4][K];
		int[][] cursor = new int[4][4];
		for (int i = 0; i < K; i++) {
			int a = Integer.parseInt(A[i]);
			int b = Integer.parseInt(B[i]);
			pieces[a][b][cursor[a][b]] = i + 1;
			cursor[a][b]++;
		}
		
		/**
		 * 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 = 0; k < cursor[i][j]; k++) {
					for (int u = 0; u < j; u++) {
						for (int v = 0; v < i; v++) {
							output[u][x + v] = pieces[i][j][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 = cursor[2][2];
		int a1 = cursor[1][1];
		int a2 = cursor[1][2];
		int a3 = cursor[1][3];
		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][b2];
				output[2][xx + 1] = pieces[1][2][b2];
				b2++;
				xx += 2;
			} else if (b3 < a3 && xx + 3 <= 2 * sq) {
				output[2][xx] = pieces[1][3][b3];
				output[2][xx + 1] = pieces[1][3][b3];
				output[2][xx + 2] = pieces[1][3][b3];
				b3++;
				xx += 3;
			} else if (xx < 2 * sq) {
				output[2][xx] = pieces[1][1][b1];
				b1++;
				xx++;
			}
		}
		
		/**
		 * Je finis de placer les 1x? résiduels.
		 */
		for (; b3 < a3; b3++) {
			output[0][x] = pieces[1][3][b3];
			output[1][x] = pieces[1][3][b3];
			output[2][x] = pieces[1][3][b3];
			x++;
		}
		for (; b2 + 3 <= a2; b2 += 3) {
			output[0][x] = pieces[1][2][b2];
			output[0][x + 1] = pieces[1][2][b2];
			output[1][x] = pieces[1][2][b2 + 1];
			output[1][x + 1] = pieces[1][2][b2 + 1];
			output[2][x] = pieces[1][2][b2 + 2];
			output[2][x + 1] = pieces[1][2][b2 + 2];
			x += 2;
		}
		for (; b1 + 3 <= a1; b1 += 3) {
			output[0][x] = pieces[1][1][b1];
			output[1][x] = pieces[1][1][b1 + 1];
			output[2][x] = pieces[1][1][b1 + 2];
			x++;
		}
		for (; b2 < a2; b2++) {
			output[0][x] = pieces[1][2][b2];
			output[1][x] = pieces[1][2][b2];
			output[2][x] = pieces[1][1][b1];
			b1++;
			x++;
		}
		
		/**
		 * J'imprime le tout.
		 */
		for (int i = 0; i < 3; i++) {
			StringJoiner sj = new StringJoiner(" ");
			for (int k : output[i]) {
				sj.add(Integer.toString(k));
			}
			System.out.println(sj.toString());
		}
	}

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

