#include <bits/stdc++.h>
using namespace std;
set<string> S;
void itswacky() {
  long long int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s1, s2;
    cin >> s1;
    cin >> s2;
    string A = string(1, s1[0]);
    string B = string(1, s1[1]);
    string C = string(1, s2[0]);
    string D = string(1, s2[1]);
    if (S.find(A + B + D + C) != S.end()) {
      S.insert(A + B + D + C);
    } else if (S.find(A + B + D + C) != S.end()) {
      S.insert(A + B + D + C);
    } else if (S.find(B + D + C + A) != S.end()) {
      S.insert(B + D + C + A);
    } else if (S.find(D + C + A + B) != S.end()) {
      S.insert(D + C + A + B);
    } else if (S.find(C + A + B + D) != S.end()) {
      S.insert(C + A + B + D);
    } else {
      S.insert(A + B + D + C);
    }
    if (i < n - 1) {
      string at;
      cin >> at;
    }
  }
  cout << S.size() << '\n';
  ;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  while (t--) {
    itswacky();
  }
  return 0;
}
