#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i;
  char ch[6];
  while (cin >> n) {
    getchar();
    set<string> S;
    set<string>::iterator it;
    int cnt = 0;
    for (i = 1; i <= n; i++) {
      scanf("%c%c\n", &ch[0], &ch[1]);
      scanf("%c%c\n", &ch[2], &ch[3]);
      scanf("**\n");
      ch[4] = '\0';
      it = S.find(ch);
      if (it == S.end()) {
        cnt++;
        S.insert(ch);
        char tmp[6];
        tmp[4] = '\0';
        tmp[0] = ch[2], tmp[1] = ch[0];
        tmp[2] = ch[3], tmp[3] = ch[1];
        S.insert(tmp);
        tmp[0] = ch[3], tmp[1] = ch[2];
        tmp[2] = ch[1], tmp[3] = ch[0];
        S.insert(tmp);
        tmp[0] = ch[1], tmp[1] = ch[3];
        tmp[2] = ch[0], tmp[3] = ch[2];
        S.insert(tmp);
      }
    }
    cout << cnt << endl;
  }
}
