#include <bits/stdc++.h>
using namespace std;

struct Dice{
    int t,f;
    vector<int> value;
    Dice(){
        t = f = -1;
    }
    Dice(int t, int f){
        this->t = t;
        this->f = f;
        v_set();
    }
    void init(int t, int f){
        this->t = t;
        this->f = f;
        v_set();
    }
    int side_ret(){
        int ret;

        if(t == 1){
            if(f == 2){
                ret = 3;
            }
            else if(f == 3){
                ret = 5;
            }
            else if(f == 4){
                ret = 2;
            }
            else if(f == 5){
                ret = 4;
            }
        }
        else if(t == 2){
            if(f == 1){
                ret = 4;
            }
            else if(f == 3){
                ret = 1;
            }
            else if(f == 4){
                ret = 6;
            }
            else if(f == 6){
                ret = 3;
            }
        }
        else if(t == 3){
            if(f == 1){
                ret = 2;
            }
            else if(f == 2){
                ret = 6;
            }
            else if(f == 5){
                ret = 1;
            }
            else if(f == 6){
                ret = 5;
            }
        }
        else if(t == 4){
            if(f == 1){
                ret = 5;
            }
            else if(f == 2){
                ret = 1;
            }
            else if(f == 5){
                ret = 6;
            }
            else if(f == 6){
                ret = 2;
            }
        }
        else if(t == 5){
            if(f == 1){
                ret = 3;
            }
            else if(f == 3){
                ret = 6;
            }
            else if(f == 4){
                ret = 1;
            }
            else if(f == 6){
                ret = 4;
            }
        }
        else if(t == 6){
            if(f == 2){
                ret = 4;
            }
            else if(f == 3){
                ret = 2;
            }
            else if(f == 4){
                ret = 5;
            }
            else if(f == 5){
                ret = 3;
            }
        }

        return ret;
    }

    void v_set(){

        value.resize(6);

        value[0] = f;
        value[1] = t;
        value[2] = 7-f;
        value[3] = 7-t;
        value[4] = side_ret();
        value[5] = 7 - value[4];

    }

    void px_rot(){

        vector<int> tmp = value;

        value[1] = tmp[5];
        value[5] = tmp[3];
        value[3] = tmp[4];
        value[4] = tmp[1];

        f = value[0];
        t = value[1];

    }

    void nx_rot(){

        vector<int> tmp = value;

        value[1] = tmp[4];
        value[3] = tmp[5];
        value[4] = tmp[3];
        value[5] = tmp[1];

        f = value[0];
        t = value[1];

    }

    void py_rot(){

        vector<int> tmp = value;

        value[0] = tmp[3];
        value[1] = tmp[0];
        value[2] = tmp[1];
        value[3] = tmp[2];

        f = value[0];
        t = value[1];

    }

    void ny_rot(){

        vector<int> tmp = value;

        value[0] = tmp[1];
        value[1] = tmp[2];
        value[2] = tmp[3];
        value[3] = tmp[0];

        f = value[0];
        t = value[1];

    }
};

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

int main() {

    while(true){

        int n;
        cin >> n;

        if(n == 0){
            break;
        }

        Dice d[n];

        for(int i=0; i<n; i++){
            int t,f;
            cin >> t >> f;
            d[i].init(t,f);
        }

        stack<Dice> area[50][50];

        const int center = 25;

        for(int i=0; i<n; i++){
            area[center][center].push(d[i]);
            int px = center, py = center;
            while(true) {
                int now_stack_size = area[px][py].size();
                int maxd = -1;
                int index = -1;
                for (int j = 0; j < 4; j++) {
                    if (now_stack_size - 1 > area[px + dx[j]][py + dy[j]].size()) {
                        if (dx[j] == 1) {
                            if(d[i].value[4] == 4 || d[i].value[4] == 5 || d[i].value[4] == 6){
                                if(maxd < d[i].value[4]) {
                                    maxd = d[i].value[4];
                                    index = 1;
                                }
                            }

                        } else if (dx[j] == -1) {
                            if(d[i].value[5] == 4 || d[i].value[5] == 5 || d[i].value[5] == 6){
                                if(maxd < d[i].value[5]) {
                                    maxd = d[i].value[5];
                                    index = 3;
                                }
                            }
                        } else if (dy[j] == -1) {
                            if(d[i].f == 4 || d[i].f == 5 || d[i].f == 6) {
                                if (maxd < d[i].f) {
                                    maxd = d[i].f;
                                    index = 2;
                                }
                            }
                        } else if (dy[j] == 1) {
                            if(d[i].f == 1 || d[i].f == 2 || d[i].f == 3){
                                if(maxd < 7-d[i].f){
                                    maxd = 7 - d[i].f;
                                    index = 0;
                                }
                            }
                        }
                    }
                }

                if (maxd != -1) {
                    area[px][py].pop();
                    if(index == 0){
                        d[i].py_rot();
                        px += dx[index];
                        py += dy[index];
                    }
                    else if(index == 1){
                        d[i].px_rot();
                        px += dx[index];
                        py += dy[index];
                    }
                    else if(index == 2){
                        d[i].ny_rot();
                        px += dx[index];
                        py += dy[index];
                    }
                    else if(index == 3){
                        d[i].nx_rot();
                        px += dx[index];
                        py += dy[index];
                    }
                    area[px][py].push(d[i]);
                }
                else{
                    break;
                }
            }
        }

        int ans[6] = {0};

        for(int i=0; i<50; i++){
            for(int j=0; j<50; j++){
                if(!area[i][j].empty()){
                    ans[area[i][j].top().t - 1]++;
                }
            }
        }

        cout << ans[0];

        for(int i=1; i<6; i++){
            cout << " " << ans[i];
        }

        cout << endl;

    }



    return 0;
}


Measured memory_bytes: 4856