dice ='253416'
def rot(d, k)
  case(k)
  when 0,2
    3.times {rot(d,k | 1) }
  when 1
    d[1], d[5], d[0], d[4]= d[4], d[1], d[5], d[0]
  when 3
    d[3], d[5], d[2], d[4] = d[4], d[3], d[5], d[2]
  else
    d[0], d[2], d[1], d[3] = d[3], d[0], d[2], d[1]
  end
end
loop do
  break if (n=gets.to_i) == 0
  map = Hash.new([])
  n.times do
    t,f = gets.split
    d = dice.clone
    catch(:found) do
      6.times do |i|
        4.times do 
          rot(d, 4)
          throw :found if d[2] == f && d[4] == t
        end
        rot(d, i.even? ? 0 : 2)
      end
    end
    x,y = 0,0
    loop do
      map[[x,y]] = map[[x,y]] + [d[4]]
      dx,dy = [-1,1,0,0],[0,0,1,-1]
      mv, dv = 0, -1
      for i in 0..3
        if map[[x+dx[i],y+dy[i]]].size < map[[x,y]].size - 1 && d[i].to_i > dv
          dv, mv = d[i].to_i,i
        end
      end
      break if dv <= 3
      map[[x,y]].pop
      rot(d,mv)
      x, y = x + dx[mv], y + dy[mv]
    end
  end
  res = [0,0,0,0,0,0]
  map.each {|k,v| res[v.pop.to_i - 1] += 1 } 
  puts res.join(' ')
end