#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = ((int)b) - 1; i >= ((int)a); --i)
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

void dump_impl(string s) {}
template <class H, class... T>
void dump_impl(string s, H head, T... tail) {
    int p = 0;
    rep(i, 0, sz(s)) {
        char x = s[i];
        if (p == 0 && x == ',') {
            cerr << "=" << head << ", ";
            dump_impl(s.substr(i + 1), tail...);
            return;
        } else {
            cerr << x;
            if (x == '(') p++;
            if (x == ')') p--;
        }
    }
}
#ifdef LOCAL
#define dump(...) do { cerr << "\x1b[33;1m"; dump_impl(#__VA_ARGS__ ",", __VA_ARGS__); cerr << "\x1b[0m" << endl; } while (0) 
#else
#define dump(...)
#endif

constexpr int DY[8] = {-1, 0, 1, 0, -1, 1, 1, -1};
constexpr int DX[8] = {0, 1, 0, -1, 1, 1, -1, -1};

template <class K = int>
struct Dice {
    enum FACE { T, B, N, E, S, W };
    array<K, 6> face;
    Dice(K t = 1, K b = 6, K n = 2, K e = 3, K s = 5, K w = 4) {
        face[T] = t; face[B] = b; face[N] = n;
        face[E] = e; face[S] = s; face[W] = w;
    }
    void rotate(int dir) {
        vector<int> seq;
        switch (dir) {
            case 0:
                seq = {T, S, B, N};
                break;
            case 1:
                seq = {T, W, B, E};
                break;
            case 2:
                seq = {T, N, B, S};
                break;
            case 3:
                seq = {T, E, B, W};
                break;
            default:
                assert(false);
                break;
        }
        auto old = face;
        rep(i, 0, 4) {
            face[seq[(i + 1) % 4]] = old[seq[i]];
        }
    }

    K get(FACE f) { return face[f]; }

    bool operator<(const Dice &r) const {
        return face[T] == r.face[T] ?
            (face[S] < r.face[S]) : (face[T] < r.face[T]);
    }
};

void solve(int N) {
    vector<pii> TF(N);
    vector<Dice<>> dice(N);
    rep(i, 0, N) {
        int t, f;
        cin >> t >> f;
        int right = 0;
        if (t == 1) {
            if (f == 3) right = 5;
            if (f == 2) right = 3;
            if (f == 5) right = 4;
            if (f == 4) right = 2;
        }
        if (t == 2) {
            if (f == 1) right = 4;
            if (f == 3) right = 1;
            if (f == 6) right = 3;
            if (f == 4) right = 6;
        }
        if (t == 3) {
            if (f == 6) right = 5;
            if (f == 5) right = 1;
            if (f == 1) right = 2;
            if (f == 2) right = 6;
        }
        if (t == 4) {
            if (f == 6) right = 2;
            if (f == 5) right = 6;
            if (f == 1) right = 5;
            if (f == 2) right = 1;
        }
        if (t == 5) {
            if (f == 1) right = 3;
            if (f == 3) right = 6;
            if (f == 6) right = 4;
            if (f == 4) right = 1;
        }
        if (t == 6) {
            if (f == 3) right = 2;
            if (f == 2) right = 4;
            if (f == 5) right = 3;
            if (f == 4) right = 5;
        }
        // dump(right);
        dice[i] = Dice<>(t, 7 - t, 7 - f, right, f, 7 - right);
    }

    vector<vvi> idx(100, vvi(100, vi(100, -1)));
    rep(i, 0, 100) rep(j, 0, 100) {
        idx[0][i][j] = 1000000;
    }
    int ofs = 50;

    auto fall = [&](auto fn, int i, int z, int y, int x) -> tuple<int, int, int> {
        if (idx[z - 1][y][x] == -1) {
            return fn(fn, i, z - 1, y, x);
        }
        assert(idx[z][y][x] == -1);

        int mx = 0;
        int dir = -1;
        vector<Dice<>::FACE> face = {Dice<>::S, Dice<>::W, Dice<>::N, Dice<>::E};
        rep(f, 0, sz(face)) {
            auto tmp = dice[i].get(face[f]);
            int yy = y + DY[f];
            int xx = x + DX[f];
            if (idx[z    ][yy][xx] != -1) continue;
            if (idx[z - 1][yy][xx] != -1) continue;
            if (tmp != 4 && tmp != 5 && tmp != 6) continue;
            if (mx < tmp) {
                mx = tmp;
                dir = f;
            }
        }
        
        if (dir == -1) {
            return make_tuple(z, y, x);
        } else {
            int yy = y + DY[dir];
            int xx = x + DX[dir];
            int zz = z - 1;
            // dump(i, dir);
            dice[i].rotate(dir);
            return fn(fn, i, zz, yy, xx);
        }
    };

    rep(i, 0, N) {
        int y = ofs + 0;
        int x = ofs + 0;
        auto pos = fall(fall, i, 100, y, x);
        int z;
        tie(z, y, x) = pos;
        // dump(i, z, y, x);

        idx[z][y][x] = i;
    }

    vi ans(6);
    rep(y, 0, 100) {
        rep(x, 0, 100) {
            rrep(z, 0, 100) {
                if (idx[z][y][x] != -1) {
                    if (idx[z][y][x] < N) {
                        int v = dice[idx[z][y][x]].get(Dice<>::T);
                        // dump(v);
                        ans[v - 1]++;
                    }
                    break;
                }
            }
        }
    }
    rep(i, 0, sz(ans)) {
        if (i != 0) cout << " ";
        cout << ans[i];
    }
    cout << endl;
}

signed main() {
    while (1) {
        int N;
        cin >> N;
        if (N == 0) break;
        solve(N);
    }
}


Measured memory_bytes: 11348