#include <bits/stdc++.h>
using namespace std;
int N;
set<string> s;
int main() {
  scanf("%d", &N);
  s.clear();
  for (int i = 0; i < N; ++i) {
    char ch[5];
    scanf("%s", ch);
    scanf("%s", ch + 2);
    char t[3];
    scanf("%s", t);
    t[0] = ch[2], ch[2] = ch[3], ch[3] = t[0];
    string temp = ch;
    string Min = temp;
    for (int j = 0; j < 4; ++j) {
      temp = temp[3] + temp.substr(0, 3);
      Min = min(temp, Min);
    }
    s.insert(Min);
  }
  printf("%d\n", s.size());
  return 0;
}
