#include <bits/stdc++.h>
using namespace std;
int n;
int dis[1000][4];
bool isMatch(int a, int b) {
  for (int i = 0; i < 4; i++) {
    bool m = true;
    for (int j = 0; j < 4; j++) {
      int jp = (j + i) % 4;
      if (dis[a][j] != dis[b][jp]) {
        m = false;
        break;
      }
    }
    if (m) return true;
  }
  return false;
}
int main() {
  cin >> n;
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (i > 0) {
      string c;
      cin >> c;
    }
    int a, b;
    cin >> a >> b;
    dis[i][0] = a / 10;
    dis[i][1] = a % 10;
    dis[i][2] = b % 10;
    dis[i][3] = b / 10;
    bool distinct = true;
    for (int j = 0; j < i; j++) {
      if (isMatch(j, i)) {
        distinct = false;
        break;
      }
    }
    if (distinct) count++;
  }
  cout << count << endl;
  return 0;
}
