const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const inputs = input.trim().split('\n');
const n = Number(inputs[0]);
const adj = inputs.slice(1).map((s) => s.split(' ').map(Number));

class Edge {
  constructor(dest, weight = 1) {
    this.dest = dest;
    this.weight = weight;
  }
}

class GraphList {
  constructor(n) {
    this.n = n;
    this.adj = {};
  }
  addEdge(source, edge) {
    this.adj[source] = this.adj[source] || [];
    this.adj[source].push(edge);
  }
  forEach(iterator) {
    Object.keys(this.adj).forEach(source => {
      this.adj[source].forEach(edge => iterator(Number(source), edge));
    });
  }
}

class GraphMatrix {
  constructor(n) {
    this.matrix = (new Array(n)).fill(0).map(() => (new Array(n)).fill(0));
  }
  fetchGraphList(graphList) {
    graphList.forEach(this.addEdge.bind(this));
  }
  addEdge(source, edge) {
    this.matrix[source - 1][edge.dest - 1] = edge.weight;
  }
  toString() {
    return this.matrix.map(list => list.join(' ')).join('\n');
  }
}

const graphList = new GraphList(n);
for (let i = 0; i < n; i++) {
  const u = adj[i][0];
  const k = adj[i][1];
  const vj = adj[i].slice(2);
  for (let j = 0; j < k; j++) {
    graphList.addEdge(u, new Edge(vj[j]));
  }
}
const graphMatrix = new GraphMatrix(n);
graphMatrix.fetchGraphList(graphList);
console.log(graphMatrix.toString());

