#include <bits/stdc++.h>
using namespace std;
map<string, int> memo;
int piles = 0;
string m;
bool is_new(string s) {
  if (memo[s]) return false;
  s += s;
  for (int i = 0; i < 4; i++) {
    m = "";
    for (int j = 0; j < 4; j++) m += s[i + j];
    memo[m] = 1;
  }
  return true;
}
int main() {
  int n;
  string s, t;
  cin >> n;
  int result = 0;
  while (n--) {
    cin >> s >> t;
    s += t[1];
    s += t[0];
    cin >> t;
    result += is_new(s);
  }
  cout << result << endl;
}
