class Die
    def initialize(t, f)
        @top, @left, @front = 1, 2, 3

        if bottom == t
            @top, @left = bottom, right
        elsif top != t
            spin until front == t
            @top, @front = front, bottom
        end
        spin until front == f

        @x = @y = 0
    end
    attr_reader :top, :front, :left, :x, :y

    def spin
        @front, @left = right, front
    end

    def bottom
        7 - top
    end

    def back
        7 - front
    end

    def right
        7 - left
    end

    def rollable(i, board)
        h = board[[@x, @y]].size
        case i
            when front then return board[[@x, @y-1]].size < h
            when back  then return board[[@x, @y+1]].size < h
            when left  then return board[[@x-1, @y]].size < h
            when right then return board[[@x+1, @y]].size < h
        end
        false
    end

    def roll(i)
        case i
        when front
            @top, @front = back, top
            @y -= 1
        when back
            @top, @front = front, bottom
            @y += 1
        when left
            @left, @top = top, right
            @x -= 1
        when right
            @left, @top = bottom, left
            @x += 1
        end
    end
end


loop do
    n = gets.to_i
    break if n == 0

    board = Hash.new([])
    n.times do
        die = Die.new(*gets.split.map(&:to_i))
        loop do
            rolled = false
            [6, 5, 4].each do |i|
                if die.rollable(i, board)
                    die.roll(i)
                    rolled = true
                    break
                end
            end
            break unless rolled
        end
        a = board[[die.x, die.y]]
        if a.empty?
            board[[die.x, die.y]] = [die]
        else
            a << die
        end
    end
    count = [0] * 6
    board.each_value do |dice|
        count[dice.last.top - 1] += 1
    end
    puts count * ' '
end