#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef pair<int,int> P;

//高さ,上
vector<P> vec[200][200];
const int L=100,R=100;

//上:0,下:1,右:2,左:3,手前:4,奥:5
struct Dice{
    vector<int> f={1,6,5,2,3,4};
    //回転後に上になる面を返す
    int Rotate(int dir,bool plus){
        //(+X,+Y,Z(上から見て左回り) axis rotate)
        if(plus){
            if(dir == 0){
                swap(f[0],f[2]),swap(f[0],f[1]),swap(f[0],f[3]);
            }else if(dir == 1){
                swap(f[0],f[5]),swap(f[0],f[1]),swap(f[0],f[4]);
            }else{
                swap(f[2],f[5]),swap(f[2],f[3]),swap(f[2],f[4]);
            }
        }else{
            if(dir == 0){
                swap(f[0],f[3]),swap(f[0],f[1]),swap(f[0],f[2]);
            }else if(dir == 1){
                swap(f[0],f[4]),swap(f[0],f[1]),swap(f[0],f[5]);
            }else{
                swap(f[2],f[4]),swap(f[2],f[3]),swap(f[2],f[5]);
            }
        }
        return f[0];
    }
    void Arrange(int id1, int num1, int id2, int num2){
        while(1){
            if(f[id1] == num1 && f[id2] == num2){
                return;
            }
            Rotate(rand()%3,true);
        }
    }
};

const int dx[4] = {-1,1,0,0};
const int dy[4] = {0,0,-1,1};

int main()
{
    while(1){
        int n;
        cin >> n;
        if(n == 0){
            break;
        }
        rep(i,200){
            rep(j,200){
                vec[i][j].clear();
            }
        }
        vector<Dice> dice(n);
        rep(i,n){
            int t,f;
            cin >> t >> f;
            int nx = L, ny = R, nz;
            dice[i].Arrange(0,t,4,f);
            while(1){
                if(!vec[nx][ny].empty()){
                    nz = vec[nx][ny].back().fi+1;
                }else{
                    vec[nx][ny].pb(P(0,dice[i].f[0]));
                    break;
                }
                int mn = 4;
                P next = P(-1,-1);
                rep(j,2){
                    rep(k,2){
                        int xx = nx + dx[2*j+k], yy = ny + dy[2*j+k];
                        if(vec[xx][yy].empty() || vec[xx][yy].back().fi < nz-1){
                            dice[i].Rotate(j,k);
                            if(dice[i].f[0] < mn){
                                mn = dice[i].f[0];
                                next = P(j,k);
                            }
                            dice[i].Rotate(j,k^1);
                        }
                    }
                }
                if(mn == 4){
                    vec[nx][ny].pb(P(nz,dice[i].f[0]));
                    // cout << nz << " " << dice[i].f[0] << "\n";
                    break;
                }else{
                    nx += dx[2*next.fi+next.se], ny += dy[2*next.fi+next.se];
                    dice[i].Rotate(next.fi,next.se);
                }
            }
        }
        int ans[6] = {};
        rep(j,200){
            rep(k,200){
                if(!vec[j][k].empty()) ans[vec[j][k].back().se-1]++;
            }
        }
        rep(i,5){
            cout << ans[i] << " ";
        }
        cout << ans[5] << "\n";
    }
}



Measured memory_bytes: 4040