#include <bits/stdc++.h>
using namespace std;
struct p {
  int k[4];
};
p povorot(p a) {
  int t = a.k[0];
  a.k[0] = a.k[3];
  a.k[3] = a.k[2];
  a.k[2] = a.k[1];
  a.k[1] = t;
  return a;
}
bool operator==(p a, p b) {
  for (int i = 0; i < 4; i++) {
    bool q = true;
    for (int j = 0; j < 4; j++)
      if (a.k[j] != b.k[j]) q = false;
    if (q) return true;
    a = povorot(a);
  }
  return false;
}
p f[1010], cur;
int n, k;
void solve() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    cur.k[0] = a / 10;
    cur.k[1] = a % 10;
    cur.k[2] = b % 10;
    cur.k[3] = b / 10;
    bool fm = false;
    for (int j = 0; j < k; j++)
      if (cur == f[j]) {
        fm = true;
        break;
      }
    if (!fm) f[k++] = cur;
  }
  cout << k << endl;
}
int main() {
  solve();
  return 0;
}
