#include<iostream>
#include<vector>
#include<algorithm>
#include<cassert>

#define TOP 0
#define BOTTOM 1
#define NORTH 2
#define SOUTH 3
#define WEST 4
#define EAST 5

class Dice{

public:
  int top,bottom,north,south,west,east;

  Dice(){}
  Dice(int t, int b, int n, int s, int w, int e)
    :top(t),bottom(b),north(n),south(s),west(w),east(e){}

  void setDice(int t, int b, int n, int s, int w, int e){
    top = t; bottom = b, north = n; south = s, west = w; east = e;
  }


  //print all variable
  void printAll() const{
    std::cout << "top " << top;
    std::cout << " bottom " << bottom;
    std::cout << " north " << north;
    std::cout << " south " << south;
    std::cout << " west " << west;
    std::cout << " east " << east << std::endl;
  }

  //in for loop this function is convenient
  //able to access variables like array
  //this function can only get specific variable
  int getAt(int pos) const {
    if(pos == TOP) return top;
    if(pos == BOTTOM) return bottom;
    if(pos == NORTH) return north;
    if(pos == SOUTH) return south;
    if(pos == WEST) return west;
    if(pos == EAST) return east;
  }
  
  //in for loop this function is convenient
  //able to access variables like array
  //this function can set a value to specific variable
  int setAt(int pos, int n){
    if(pos == TOP) top = n;
    if(pos == BOTTOM) bottom = n;
    if(pos == NORTH) north = n;
    if(pos == SOUTH) south = n;
    if(pos == WEST) west = n;
    if(pos == EAST) east = n;
  }

  void rotateNorth(){setDice(south,north,top,bottom,west,east);}
  void rotateSouth(){setDice(north,south,bottom,top,west,east);}
  void rotateEast(){setDice(west,east,north,south,bottom,top);}
  void rotateWest(){setDice(east,west,north,south,top,bottom);}
  void rotateCW(){setDice(top,bottom,west,east,south,north);}
  void rotateCCW(){setDice(top,bottom,east,west,north,south);}

  bool operator == (const Dice& d) const{
    int D1[] = {top,bottom,north,south,west,east};
    int D2[] = {d.top,d.bottom,d.north,d.south,d.west,d.east};

    for(int i = 0; i < 6; i++)
      if(D1[i] != D2[i] && D1[i] != -1 && D2[i] != -1) return false;
    return true;
  };

  // decide dice from dice including wild card (-1);
  Dice find(int t, int b, int n, int s, int w, int e){
    Dice base(t,b,n,s,w,e);
    Dice d(1,6,5,2,4,3);

    if(base.top != -1) base.bottom = 7-base.top;
    if(base.bottom != -1) base.top = 7-base.bottom;
    if(base.north != -1) base.south = 7-base.north;
    if(base.south != -1) base.north = 7-base.south;
    if(base.west != -1) base.east = 7-base.west;
    if(base.east != -1) base.west = 7-base.east;
    

    for(int i = 0; i < 4; i++){
      for(int j = 0; j < 4; j++){
	if(d == base) return d;
	d.rotateCW();
      }
      d.rotateNorth();
    }

    for(int i = 0; i < 4; i++){
      for(int j = 0; j < 4; j++){
	if(d == base) return d;
	d.rotateCW();
      }
      d.rotateWest();
    }

    //could not find
    return Dice(0,0,0,0,0,0);
  }
};

using namespace std;

const int MAX = 200;
vector<Dice> V[MAX][MAX];
int n;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

//east, west, south, north

void init(){
  for(int i = 0; i < MAX; i++)
    for(int j = 0; j < MAX; j++) V[i][j].clear();
}

void print(){
  for(int i = 95; i < 105; i++){
    for(int j = 95; j < 105; j++) cout << V[i][j].size();
    cout << endl;
  }
  cout << endl;
}

int able(int x, int y, Dice d){

  vector<int> C;

  for(int i = 0; i < 4; i++){
    if(V[y][x].size() > V[y+dy[i]][x+dx[i]].size()) C.push_back(i);
  }
  
  int dir = -1,mv = -1;
  for(int i = 0; i < C.size(); i++){
    int num = C[i];
    
    if(num == 0 && d.east > 3 && mv < d.east){dir = num;mv = d.east;}
    if(num == 1 && d.west > 3 && mv < d.west){dir=num;mv=d.west;}
    if(num == 2 && d.south > 3 && mv < d.south){dir=num;mv=d.south;}
      if(num == 3 && d.north > 3 && mv < d.north){dir=num;mv=d.north;}
  }
  return dir;
}

void drop(int x, int y, Dice d){

  int nowx = x;
  int nowy = y;

  while(1){
    int dir = able(nowx,nowy,d);
    if(dir == -1) break;
    nowx+=dx[dir];
    nowy+=dy[dir];
    if(dir == 0) d.rotateEast();
    if(dir == 1) d.rotateWest();
    if(dir == 2) d.rotateSouth();
    if(dir == 3) d.rotateNorth();
  }
  //  cout << "put x " << nowx << " y " << nowy << endl;
  V[nowy][nowx].push_back(d);
}

void solve(){
  
  //drop position x, y
  int dpx = 100, dpy = 100;
  
  for(int i = 0; i < n; i++){
    int top, nor;
    cin >> top >> nor;
    Dice d;
    d = d.find(top,-1,nor,-1,-1,-1);
    assert(!(d == Dice(0,0,0,0,0,0)));

    if(i)drop(dpx, dpy, d);
    else V[dpx][dpy].push_back(d);
    //print();
  }

  int ans[7] = {0};

  for(int i = 0; i < MAX; i++)
    for(int j = 0; j < MAX; j++)
      if(V[i][j].size() > 0) ans[V[i][j].back().top]++;
      
  for(int i = 1; i < 7; i++){
    if(i!=1) cout << " ";
    cout << ans[i];
  }
  cout << endl;
}

int main(){
  while(cin >> n && n){
    init();
    solve();
  }
  return 0;
}

Measured memory_bytes: 2168