#include <bits/stdc++.h>
using namespace std;
struct hoho {
  long long u, v;
};
string a, b, tmp, trash;
long long num, DD[10000], n, res, kt;
hoho change[100];
int main() {
  change[0].u = 0;
  change[0].v = 1;
  change[1].u = 1;
  change[1].v = 3;
  change[2].u = 2;
  change[2].v = 3;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    kt = 0;
    cin >> a >> b >> trash;
    tmp = a + b;
    for (int j = 1; j <= 4; j++) {
      for (int k = 0; k <= 2; k++) swap(tmp[change[k].u], tmp[change[k].v]);
      stringstream ss;
      ss << tmp;
      ss >> num;
      if (DD[num] == 0)
        DD[num] = 1;
      else
        kt++;
    }
    if (kt < 4) res++;
  }
  cout << res;
  return 0;
}
