#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  cout.tie(0);
  int n;
  int e = 0;
  string str;
  char a, b, c, d;
  pair<string, int> sum[1005];
  for (int i = 0; i < 1000; ++i) {
    sum[i].first = "";
  }
  cin >> n;
  int ch = 1;
  cin >> a >> b;
  cin >> c >> d;
  string cur = "", cur1 = "", cur2 = "", cur3 = "";
  cin >> str;
  int p = 0;
  p = min((a - 48), min((b - 48), min((c - 48), (d - 48))));
  if (p == a - 48) {
    sum[ch].first += a;
    sum[ch].first += b;
    sum[ch].first += d;
    sum[ch].first += c;
  } else if (p == b - 48) {
    sum[ch].first += b;
    sum[ch].first += d;
    sum[ch].first += c;
    sum[ch].first += a;
  } else if (p == d - 48) {
    sum[ch].first += d;
    sum[ch].first += c;
    sum[ch].first += a;
    sum[ch].first += b;
  } else if (p == c - 48) {
    sum[ch].first += c;
    sum[ch].first += a;
    sum[ch].first += b;
    sum[ch].first += d;
  }
  sum[ch].second = 1;
  for (int i = 0; i < n - 1; ++i) {
    cur = "";
    cur1 = "";
    cur2 = "";
    cur3 = "";
    e = 0;
    cin >> a >> b;
    cin >> c >> d;
    cin >> str;
    p = min((a - 48), min((b - 48), min((c - 48), (d - 48))));
    cur += a;
    cur += b;
    cur += d;
    cur += c;
    cur1 += b;
    cur1 += d;
    cur1 += c;
    cur1 += a;
    cur2 += d;
    cur2 += c;
    cur2 += a;
    cur2 += b;
    cur3 += c;
    cur3 += a;
    cur3 += b;
    cur3 += d;
    for (int i = 1; i <= ch; ++i) {
      if (cur == sum[i].first || cur1 == sum[i].first || cur2 == sum[i].first ||
          cur3 == sum[i].first) {
        sum[i].second = 1;
        ++e;
        break;
      }
    }
    if (e == 0) {
      ++ch;
      sum[ch].first = cur;
      sum[ch].second = 1;
    }
  }
  cout << ch;
  return 0;
}
