/*
 * Author:  xioumu
 * Created Time:  2012/7/17 13:33:03
 * File Name: c.cpp
 * solve: c.cpp
 */
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>
#include<set>
using namespace std;
const double esp = 1e-8;
const int maxn = 1007;
typedef long long ll;
int left[10][10] = {{0},  //ff, tt = tt
                    {0, -1, 3, 5, 2, 4, -1},
                    {0, 4, -1, 1, 6, -1, 3},
                    {0, 2, 6, -1, -1, 1, 5},
                    {0, 5, 1, -1, -1, 6, 2},
                    {0, 3, -1, 6, 1, -1, 4},
                    {0, -1, 4, 2, 5, 3, -1}};  
int right[10][10] = {{0},  //ff, tt = tt
                    {0, -1, 4, 2, 5, 3, -1},
                    {0, 3, -1, 6, 1, -1, 4},
                    {0, 5, 1, -1, -1, 6, 2},
                    {0, 2, 6, -1, -1, 1, 5},
                    {0, 4, -1, 1, 6, -1, 3},
                    {0, -1, 3, 5, 2, 4, -1}};
int a[200][200][200];
int n;
void turn_left(int ff, int tt, int &nff, int &ntt){
    nff = ff;
    ntt = left[ff][tt];
}
void turn_front(int ff, int tt, int &nff, int &ntt){
    nff = tt;
    ntt = 7 - ff;
}
void turn_right(int ff, int tt, int &nff, int &ntt){
    nff = ff;
    ntt = right[ff][tt];
}
void turn_back(int ff, int tt, int &nff, int &ntt){
    ntt = ff;
    nff = 7 - tt;
}
int getll(int ff, int tt){
    int nff, ntt;   
    turn_left(ff, tt, nff, ntt);
    return 7 - ntt;
}
int getrr(int ff, int tt){
    int nff, ntt;   
    turn_right(ff, tt, nff, ntt);
    return 7 - ntt;
}
void gao(int ff, int tt, int z, int x, int y){
    int nff, ntt;
    int ll, rr, bb, okl = 0, okr = 0, okb = 0, okf = 0;
    ll = getll(ff, tt);
    bb = 7 - ff;
    rr = getrr(ff, tt);
    if(a[z - 1][x][y] == 0){
        gao(ff, tt, z - 1, x, y);
        return;
    }
    else{
        if(a[z - 1][x][y + 1] == 0 && ll > 3) okl = 1;        
        if(a[z - 1][x + 1][y] == 0 && ff > 3) okf = 1;
        if(a[z - 1][x - 1][y] == 0 && bb > 3) okb = 1;
        if(a[z - 1][x][y - 1] == 0 && rr > 3) okr = 1;
        
        int nx, ny, k = -1, nff, ntt;
        if(ll > k && okl) { turn_left(ff, tt, nff, ntt); nx = x; ny = y + 1; k = ll;}
        if(rr > k && okr) { turn_right(ff, tt, nff, ntt); nx = x; ny = y - 1; k = rr;}
        if(ff > k && okf) { turn_front(ff, tt, nff, ntt); nx = x + 1; ny = y; k = ff;}
        if(bb > k && okb) { turn_back(ff, tt, nff, ntt); nx = x - 1, ny = y; k = bb;}
        if(k > 3){
            gao(nff, ntt, z - 1, nx, ny);
        }
    }
    if(!okl && !okf && !okb && !okr) {
        //printf("%d\n",a[z][x][y]);
        a[z][x][y] = tt;
        //printf("==%d %d %d==%d\n", z, x, y, tt);
        //printf("=%d %d %d %d=\n", ll, rr, ff, bb);
    }
}
void getans(){
    int ans[10] = {0};
    for(int i = 1; i <= 200; i++)
        for(int j = 1; j <= 200; j++){
            int k;
            for(k = 1; k <= n; k++)
                if(a[k][i][j] == 0) break;
            if(a[k - 1][i][j] != -1){
                ans[ a[k - 1][i][j] ]++;
                //printf("(%d %d %d %d)\n", k - 1, i, j, a[k - 1][i][j]);
            }
        }
    for(int i = 1; i < 6; i++)
        printf("%d ", ans[i]);
    printf("%d\n", ans[6]);
}
int main(){
    while(scanf("%d", &n) && n){
        int tt, ff;
        memset(a, 0, sizeof(a));
        memset(a[0], -1, sizeof(a[0]));
        for(int i = 1; i <= n; i++){
            scanf("%d%d", &tt, &ff);
            for(int j = 1; j <= n; j++)
                if(a[j][100][100] == 0){
                    gao(ff, tt, j, 100, 100);
                    break;
                }
        }
        getans();
    }
    return 0;
}

Measured memory_bytes: 31000