#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, n, j, pile = 0, k;
  cin >> n;
  map<long long int, long long int> mt;
  string s[n * 3 + 5];
  for (i = 0; i < n * 3 - 1; i++) {
    cin >> s[i];
  }
  i = 0;
  for (k = 0; k < n; k++) {
    if (mt[i] == 1) {
      i += 3;
      continue;
    }
    pile += 1;
    for (j = i + 3; j < 3 * n; j += 3) {
      if (s[i][0] == s[j][0] && s[i][1] == s[j][1] &&
          s[i + 1][0] == s[j + 1][0] && s[i + 1][1] == s[j + 1][1])
        mt[j] = 1;
      if (s[j][0] == s[i + 1][0] && s[j][1] == s[i][0] &&
          s[j + 1][0] == s[i + 1][1] && s[j + 1][1] == s[i][1])
        mt[j] = 1;
      else if (s[j][0] == s[i + 1][1] && s[j][1] == s[i + 1][0] &&
               s[j + 1][0] == s[i][1] && s[j + 1][1] == s[i][0])
        mt[j] = 1;
      else if (s[j][0] == s[i][1] && s[j][1] == s[i + 1][1] &&
               s[j + 1][0] == s[i][0] && s[j + 1][1] == s[i + 1][0])
        mt[j] = 1;
    }
    i += 3;
  }
  cout << pile;
  return 0;
}
