#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

constexpr int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
constexpr int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }

#include "bits/stdc++.h"

template<typename T>
struct Dice {
public:

	Dice(std::vector<T> v) : faces(v) {}
	void roll(char c) {
		T tmp;
		switch (c) {
		case 'N':
			tmp = faces[TOP];
			faces[TOP] = faces[FRONT];
			faces[FRONT] = faces[BOTTOM];
			faces[BOTTOM] = faces[BACK];
			faces[BACK] = tmp;
			break;
		case 'S':
			tmp = faces[TOP];
			faces[TOP] = faces[BACK];
			faces[BACK] = faces[BOTTOM];
			faces[BOTTOM] = faces[FRONT];
			faces[FRONT] = tmp;
			break;
		case 'E':
			tmp = faces[TOP];
			faces[TOP] = faces[LEFT];
			faces[LEFT] = faces[BOTTOM];
			faces[BOTTOM] = faces[RIGHT];
			faces[RIGHT] = tmp;
			break;
		case 'W':
			tmp = faces[TOP];
			faces[TOP] = faces[RIGHT];
			faces[RIGHT] = faces[BOTTOM];
			faces[BOTTOM] = faces[LEFT];
			faces[LEFT] = tmp;
			break;
		case 'R':
			tmp = faces[FRONT];
			faces[FRONT] = faces[RIGHT];
			faces[RIGHT] = faces[BACK];
			faces[BACK] = faces[LEFT];
			faces[LEFT] = tmp;
			break;
		case 'L':
			tmp = faces[FRONT];
			faces[FRONT] = faces[LEFT];
			faces[LEFT] = faces[BACK];
			faces[BACK] = faces[RIGHT];
			faces[RIGHT] = tmp;
			break;
		default:
			std::cerr << "invalid char" << endl;
			abort();
		}
	}
	T top() {
		return faces[TOP];
	}
	T front() {
		return faces[FRONT];
	}
	T left() {
		return faces[LEFT];
	}
	T back() {
		return faces[BACK];
	}
	T right() {
		return faces[RIGHT];
	}
	T bottom() {
		return faces[BOTTOM];
	}
private:
	std::vector<T> faces;
	static constexpr int TOP = 0, FRONT = 1, RIGHT = 2, LEFT = 3, BACK = 4, BOTTOM = 5;
};

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	Dice<int> die({ 1,3,5,2,4,6 });
	int n;
	while (cin >> n, n) {
		map < pii, vector<Dice<int>>> mp;
		REP(i, n) {
			int t, f;
			cin >> t >> f;
			auto d = die;
			if (d.top() != t) {
				if (d.bottom() == t)d.roll('N');
				while (d.front() != t)d.roll('R');
				d.roll('N');
			}
			while (d.front() != f)d.roll('R');
			int x = 0, y = 0;
			mp[{0, 0}].push_back(d);
			using tup = tuple<int, int, pii>;
			while (true) {
				vector<tuple<int, int, pii>> v;
				int k = mp[{x, y}].size() - 1;
				if (d.right() >= 4 && mp[{x + 1, y}].size() < k)v.push_back(tup(d.right(), 0, { x + 1,y }));
				if (d.left() >= 4 && mp[{x - 1, y}].size() < k)v.push_back(tup(d.left(), 1, { x - 1,y }));
				if (d.front() >= 4 && mp[{x, y + 1}].size() < k)v.push_back(tup(d.front(), 2, { x,y + 1 }));
				if (d.back() >= 4 && mp[{x, y - 1}].size() < k)v.push_back(tup(d.back(), 3, { x,y - 1 }));
				sort(ALL(v));
				if (v.empty())break;
				else {
					mp[{x, y}].pop_back();
					tie(x, y) = get<2>(v.back());
					int di = get<1>(v.back());
					if (di == 0)d.roll('E');
					else if (di == 1)d.roll('W');
					else if (di == 2)d.roll('S');
					else d.roll('N');
					mp[{x, y}].push_back(d);
				}
			}
		}
		vi cnt(6, 0);
		for (auto a : mp) {
			if (!a.second.empty()) {
				cnt[a.second.back().top() - 1]++;
			}
		}
		REP(i, 6) {
			cout << cnt[i] << " \n"[i == 5];
		}
	}
}


Measured memory_bytes: 3116