#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n][4];
  int l = 0;
  char l0[3], l1[3], l2[3];
  for (int i = 0; i < n; i++) {
    cin >> l0 >> l1;
    for (int j = 0; j <= l; j++) {
      if (j == l) {
        a[j][0] = l0[0];
        a[j][1] = l0[1];
        a[j][2] = l1[0];
        a[j][3] = l1[1];
        l++;
        break;
      }
      if ((a[j][0] == l0[0] && a[j][1] == l0[1] && a[j][2] == l1[0] &&
           a[j][3] == l1[1]) ||
          (a[j][0] == l0[1] && a[j][1] == l1[1] && a[j][2] == l0[0] &&
           a[j][3] == l1[0]) ||
          (a[j][0] == l1[1] && a[j][1] == l1[0] && a[j][2] == l0[1] &&
           a[j][3] == l0[0]) ||
          (a[j][0] == l1[0] && a[j][1] == l0[0] && a[j][2] == l1[1] &&
           a[j][3] == l0[1])) {
        break;
      }
    }
    if (i != n - 1) cin >> l2;
  }
  cout << l;
}
