#include <bits/stdc++.h>
using namespace std;
int main() {
  char a[10], b[10], d[10], c[1000][10];
  string w;
  int n;
  while (cin >> n) {
    int num = 0;
    for (int i = 0; i < n; i++) {
      cin >> a >> b;
      d[0] = a[0], d[1] = a[1], d[2] = b[1], d[3] = b[0];
      int f2 = 1;
      for (int j = 0; j < num; j++) {
        for (int k = 0; k < 4; k++) {
          int f = 1;
          for (int h = 0; h < 4; h++)
            if (d[h] != c[j][k + h]) {
              f = 0;
              break;
            }
          if (f) {
            f2 = 0;
            break;
          }
        }
        if (f2 == 0) break;
      }
      if (f2) {
        for (int j = 0; j < 4; j++) c[num][j] = c[num][j + 4] = d[j];
        num++;
      }
      if (i < n - 1) cin >> w;
    }
    cout << num << endl;
  }
  return 0;
}
