# [T, U, R, D, L, B]
T, U, R, D, L, B = *0..5
def top d
    d[0]
end
def roll d, w
    case w
    when U; d.values_at(D, T, R, B, L, U)
    when R; d.values_at(L, U, T, D, B, R)
    when D; d.values_at(U, B, R, T, L, D)
    when L; d.values_at(R, U, B, D, T, L)
    end
end
$r_data = [
        [0, 3, 5, 2, 4, 0],
        [4, 0, 1, 6, 0, 3],
        [2, 6, 0, 0, 1, 5],
    ]
$r_data += $r_data.map(&:reverse).reverse
$r_data
$r_data[5][3]
def init_d t, d
    r = $r_data[t-1][d-1]
    [t, 7 - d, r, d, 7 - r , 7 - t]
end

def board_near board, x, y
    [board[x][y + 1], board[x + 1][y], board[x][y - 1], board[x - 1][y]]
end

def get_sides d
    d[1..4]
end

loop do
    n = readline.to_i
    break if n == 0
    board = Array.new(300){Array.new(300){[]}}

    n.times do
        x = y = 150
        f, d = readline.split.map(&:to_i)
        c_d = init_d f, d
        loop do
            c_h = board[x][y].size
            near = board_near(board, x, y).map{|d| d.size() < c_h }
            sides = get_sides c_d
            res = near.zip(sides,1..4).select{|d, x, w| d}
            res = res.map{|x, s, w| [s, w]}.sort.reverse
            num, way = res[0]
            break unless !res.empty?  and num > 3
            
            dx = [0, 1, 0, -1]
            dy = [1, 0, -1, 0]
            x += dx[way - 1]
            y += dy[way - 1]
            c_d = roll c_d, way
        end
        board[x][y] << c_d
    end
            
        m = board.flatten(1).reject{|ds|ds.empty?}.map{|ds| top ds.last}
        res = m.reduce(Array.new(6){0}){|a, r| a[r-1] += 1; a}
        puts res.join(" ")
end