import java.io.*;
import java.lang.*;
import java.util.*;

public class D_h {
    public static final int MAX_DIM = 20;
    public static DataInputStream in = new DataInputStream(System.in);


    public static void main(String[] args) {
	int dim[] = new int[MAX_DIM];
	int SP[][] = new int[MAX_DIM][MAX_DIM];
	int n;
	boolean first = true;
	
	while ((n = read_case(dim, SP)) > 0) {
	    if (!first) {
		System.out.println("");
		System.out.println("");
	    }
	    first = false;
	    solve_case(dim, SP, n);
	}
    }


    public static int read_case(int dim[], int SP[][]) {
	int n, i, j;

	try {
	    String line = in.readLine();
	    n = Integer.parseInt(line);
	    if (n == 0) {
		return n;
	    }
	    for (i = 0; i < n; i++) {
		dim[i] = 0;
		StringTokenizer str;
		line = in.readLine();
		str = new StringTokenizer(line);
		j = Integer.parseInt(str.nextToken());
		while (j != 0) {
		    SP[i][dim[i]++] = j;
		    j = Integer.parseInt(str.nextToken());
		}
	    }
	    return n;
	} catch (IOException e) {
	    return 0;
	}
    }

    static public void solve_case(int dim[], int SP[][], int n) {
	int newSP[][] = new int[MAX_DIM][MAX_DIM];
	int i, j, k;

	for (i = 0; i < MAX_DIM; i++) {
	    for (j = 0; j < MAX_DIM; j++) {
		newSP[i][j] = 0;
	    }
	}
	for (i = 0; i < n; i++) {
	    for (j = 0; j < dim[i]; j++) {
		for (k = 0; k < SP[i][j]; k++) {
		    newSP[k][i]++;
		}
	    }
	}
	for (i = 0; i < MAX_DIM && newSP[i][0] != 0; i++) {
	    for (j = 0; j < MAX_DIM && newSP[i][j] != 0; j++) {
		if (j != 0) {
		    System.out.print(" ");
		}
		System.out.print(newSP[i][j]);
	    }
	    System.out.println("");
	}
	System.out.println("");

	/* now do the right rotation */
	for (i = 0; i < MAX_DIM; i++) {
	    for (j = 0; j < MAX_DIM; j++) {
		newSP[i][j] = 0;
	    }
	}
	for (i = 0; i < n; i++) {
	    for (j = 0; j < dim[i]; j++) {
		for (k = 0; k < SP[i][j]; k++) {
		    newSP[j][k]++;
		}
	    }
	}
	for (i = 0; i < MAX_DIM && newSP[i][0] != 0; i++) {
	    for (j = 0; j < MAX_DIM && newSP[i][j] != 0; j++) {
		if (j != 0) {
		    System.out.print(" ");
		}
		System.out.print(newSP[i][j]);
	    }
	    System.out.println("");
	}
    }
}
