#include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <cassert>

using namespace std;

typedef long long ll;
typedef ll li;
typedef pair<int,int> PI;
#define EPS (1e-6)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define REP(i, n) rep (i, n)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(),a.end()
#define CLR(a) memset((a),0,sizeof(a))
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
template<typename T,typename U> ostream& operator<< (ostream& out, const pair<T,U>& val){return out << "(" << val.F << ", " << val.S << ")";}
template<class T> ostream& operator<< (ostream& out, const vector<T>& val){out << "{";rep(i,SZ(val)) out << (i?", ":"") << val[i];return out << "}";}
typedef double FP;
typedef complex<FP> pt;
typedef pt P;
typedef pair<pt,pt> line;
FP dot(P a,P b){return (conj(a)*b).real();}
FP crs(P a,P b){return (conj(a)*b).imag();}
P crspt(P a,P b,P c,P d){b-=a,d-=c;return a+b*crs(d,c-a)/crs(d,b);}
bool onl(P a1,P a2,P b){return abs(b-a1)+abs(b-a2)<abs(a1-a2)+EPS;}
void pkuassert(bool t){t=1/t;};
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};

enum{TOP,BTM,LFT,RGT,FRT,BCK};
template<class T> T shift(T a,int b,int c,int d,int e){
  __typeof(a[0]) t=a[b];
  a[b]=a[c];a[c]=a[d];a[d]=a[e];a[e]=t;return a;
}
template<class T> T rgtin(T a){return shift(a,TOP,LFT,BTM,RGT);}
template<class T> T lftin(T a){return shift(a,TOP,RGT,BTM,LFT);}
template<class T> T frtin(T a){return shift(a,TOP,BCK,BTM,FRT);}
template<class T> T bckin(T a){return shift(a,TOP,FRT,BTM,BCK);}

map<PI,vector<int> > tf2c;
int n;

void solve(){
  map<PI,PI> cpos;
  int idx2e[]={RGT,FRT,LFT,BCK};
  rep(i,n){
    int t,f;
    cin >> t >> f;
    vector<int> cc(tf2c[mp(t,f)]);
    PI pos(0,0);
    while(true){
      if(cpos[pos].F==0){
        cpos[pos]=mp(1,cc[TOP]);
        break;
      }
      bool end=true;
      int hi=cpos[pos].F;
      int me=4;
      vector<int> nc;
      PI npos;
      rep(i,4){
        if(cc[idx2e[i]]<4) continue;
        int chi=cpos[pos].F;
        int nx=pos.F+dx[i],ny=pos.S+dy[i];
        if(cpos[mp(nx,ny)].F>=chi) continue;
        if(me>cc[idx2e[i]]) continue;
        me=cc[idx2e[i]];
        end=false;
        switch(idx2e[i]){
        case RGT:nc=rgtin(cc);break;
        case FRT:nc=frtin(cc);break;
        case LFT:nc=lftin(cc);break;
        case BCK:nc=bckin(cc);break;
        }
        npos=mp(nx,ny);
      }

      if(end){
        int hi=cpos[pos].F;
        cpos[pos]=mp(hi+1,cc[TOP]);
        break;
      }
      pos=npos;
      cc=nc;
    }
  }
  rep(i,6){
    if(i) cout << ' ';
    int cnt=0;
    FOR(it,cpos) cnt += it->S.S==i+1;
    cout << cnt;
  }
  cout << endl;
}


int main(int argc, char *argv[])
{
  vector<int> c(6);
  c[TOP]=6;
  c[BTM]=1;
  c[FRT]=4;
  c[BCK]=3;
  c[LFT]=5;
  c[RGT]=2;
  queue<vector<int> > q;
  q.push(c);
  while(!q.empty()){
    c=q.front();
    q.pop();
    if(tf2c.count(mp(c[TOP],c[FRT]))) continue;
    tf2c[mp(c[TOP],c[FRT])]=c;
    q.push(rgtin(c));
    q.push(lftin(c));
    q.push(frtin(c));
    q.push(bckin(c));    
  }
  while(cin >> n && n) solve();
  return 0;
}

Measured memory_bytes: 1232