#include <stdio.h>
#include <stdlib.h>

#define MAX_DIM 20

int dim[MAX_DIM];
int SP[MAX_DIM][MAX_DIM];
int n;

int read_case(void)
{
  int i, j;

  scanf("%d", &n);
  if (!n) {
    return 0;
  }

  for (i = 0; i < n; i++) {
    dim[i] = 0;
    while (scanf("%d", &j) == 1 && j) {
      SP[i][dim[i]++] = j;
    }
  }

  return 1;
}

void solve_case(void)
{
  int newSP[MAX_DIM][MAX_DIM];
  int i, j, k;

  /* do the left rotation first */
  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]; i++) {
    for (j = 0; j < MAX_DIM && newSP[i][j]; j++) {
      if (j) {
	printf(" ");
      }
      printf("%d", newSP[i][j]);
    }
    printf("\n");
  }
  printf("\n");

  /* 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]; i++) {
    for (j = 0; j < MAX_DIM && newSP[i][j]; j++) {
      if (j) {
	printf(" ");
      }
      printf("%d", newSP[i][j]);
    }
    printf("\n");
  }
}

int main(void)
{
  int first = 1;
  while (read_case()) {
    if (!first) {
      printf("\n\n");
    }
    first = 0;
    solve_case();
  }
  return 0;
}
