class Main
  def self.run
    house = OfficialHouse.new
    tenants = read_inputs
    tenants.each {|t| house.move_into(*t)}
    puts house.description
  end

  private

  def self.read_inputs
    n = gets.to_i
    (1..n).map {gets.split(" ").map(&:to_i)}
  end
end

class OfficialHouse
  def initialize
    @sections = (1..4).map{|n| Section.new(n)}
  end

  def description
    @sections.map {|s| s.description}.join("\n#{"#" * 20}\n")
  end

  def move_into(section, floor, room, number)
    @sections.select{|s| s.number == section}.first.move_into(floor, room, number)
  end
end

class Section
  def initialize(number)
    @number = number
    @floors = (1..3).map{|n| Floor.new(n)}
  end

  def description
    @floors.map {|f| f.description}.join("\n")
  end

  def move_into(floor, room, number)
    @floors.select{|f| f.number == floor}.first.move_into(room, number)
  end

  attr_reader :number
end

class Floor
  def initialize(number)
    @number = number
    @rooms = (1..10).map{|n| Room.new(n)}
  end

  def description
    " " << @rooms.map {|r| r.description}.join(" ")
  end

  def move_into(room, number)
    @rooms.select{|r| r.number == room}.first.move_into(number)
  end

  attr_reader :number
end

class Room
  def initialize(number)
    @number = number
    @tenant = 0
  end

  def description
    @tenant.to_s
  end

  def move_into(number)
    @tenant += number
  end

  attr_reader :number
end

Main.run