class Edge
  attr_accessor :dest, :weight
  def initialize dest, weight
    @dest = dest
    @weight = weight
  end
end


class Graph
  def initialize n
    @n = n
    @adjenceList = []
    n.times do |i|
      @adjenceList[i] = []
    end
  end

  def addEdge i, j, weight
    edge1 = Edge.new j, weight
    @adjenceList[i] << edge1
  end

  def printMatrix
    matrix = []
    @n.times do |i|
      matrix[i] = []
      @n.times do |j|
        matrix[i][j] = 0
      end
    end

    @n.times do |i|
      @adjenceList[i].each do |edge|
        matrix[i][edge.dest] = 1
      end
    end

    matrix.each do |row|
      count = 0
      row.each do |i|
        if count == 0
          print i
          count += 1
        else
          print " ", i
        end
      end
      puts ""
    end
  end
end


count = 0
n = 0
edge_data = []
STDIN.each_line {|line|
  if count == 0
    count += 1
    n = line.to_i
    next
  end

  edge_data << line
}

graph = Graph.new n.to_i
edge_data.each do |edge|
  edge_array = edge.split " "
  count = 0
  vertex = 0
  edge_array.each do |input_data|
    if count == 0
      count += 1
      vertex = input_data.to_i
      next
    end

    if count == 1
      count += 1
      next
    end

    dest = input_data.to_i
    graph.addEdge vertex - 1, dest -1, 0
  end
end

graph.printMatrix

