#include <bits/stdc++.h>
using namespace std;
bool used[1001];
char c[1001][3][3], z;
string s, sr, st;
set<char> second;
pair<int, string> pr[100001];
vector<long long> v, vc;
map<string, int> mp;
long long d[1000001];
long long ar[1000001];
long long n, m, b, a, cnt = 1, ans, mn = 99999999999;
bool check(int x, int y) {
  bool mon = 0;
  if (c[x][1][1] == c[y][1][1] && c[x][1][2] == c[y][1][2] &&
      c[x][2][1] == c[y][2][1] && c[x][2][2] == c[y][2][2])
    mon = 1;
  if (c[x][1][1] == c[y][1][2] && c[x][1][2] == c[y][2][2] &&
      c[x][2][2] == c[y][2][1] && c[x][2][1] == c[y][1][1])
    mon = 1;
  if (c[x][1][1] == c[y][2][2] && c[x][1][2] == c[y][2][1] &&
      c[x][2][1] == c[y][1][2] && c[x][2][2] == c[y][1][1])
    mon = 1;
  if (c[x][1][1] == c[y][2][1] && c[x][2][1] == c[y][2][2] &&
      c[x][2][2] == c[y][1][2] && c[x][1][2] == c[y][1][1])
    mon = 1;
  return mon;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> c[i][1][1] >> c[i][1][2];
    cin >> c[i][2][1] >> c[i][2][2];
    if (i != n) cin >> z >> z;
  }
  for (int i = 1; i <= n; i++) {
    if (used[i] == 1) continue;
    used[i] = 1;
    ans++;
    for (int j = 1; j <= n; j++) {
      if (check(i, j) == 1 && used[j] == 0) used[j] = 1;
    }
  }
  cout << ans;
}
