#include<bits/stdc++.h>
using namespace std;
string a[10005][5];
string s[10];
map<string, bool>mp, vis;
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		cin >> a[i][1] >> a[i][2] >> a[i][3] >> a[i][4];
		mp[a[i][1] + ',' + a[i][2] + ',' + a[i][3] + ',' + a[i][4]] = true;
	} 
	int cnt = 0;
	for (int i = 1; i + 3 <= n; i++) {
		s[1] = a[i][1] + ',' + a[i][2] + ',' + a[i][3] + ',' + a[i][4];
		s[2] = a[i + 3][4] + ',' + a[i + 3][3] + ',' + a[i + 3][2] + ',' + a[i + 3][1];
		s[3] = a[i + 3][1] + ',' + a[i + 2][1] + ',' + a[i + 1][1] + ',' + a[i][1];
		s[4] = a[i][4] + ',' + a[i + 1][4] + ',' + a[i + 2][4] + ',' + a[i + 3][4];
		s[5] = a[i][1] + ',' + a[i + 1][2] + ',' + a[i + 2][3] + ',' + a[i + 3][4];
		s[6] = a[i][4] + ',' + a[i + 1][3] + ',' + a[i + 2][2] + ',' + a[i + 3][1];
		vis[s[1]] = true;
		int flag = true;
		for (int j = 2; j <= 6; j++) {
			if (vis[s[j]] == true) {
				flag = false;
				cout << 1 << endl;
			}
			vis[s[j]] = true;
			if (mp[s[j]] != true) {
				flag = false;
				cout << 2 << endl;
			}
		}
		cout << endl;
		if (flag == false) {
			break;
		}
		cnt++;
		for (int j = 1; j <= 6; j++) {
			vis[s[j]] = false;
		}
	}
	printf("%d", cnt);
	return 0;
}