#include <bits/stdc++.h>
using namespace std;
bitset<7000> bit;
int main() {
  int n, count = 0;
  cin >> n;
  while (n--) {
    int int1, int2;
    string stars;
    cin >> int1 >> int2;
    if (n >= 1) cin >> stars;
    int a = int1 / 10, b = int1 % 10, c = int2 % 10, d = int2 / 10;
    int i1 = 1000 * a + 100 * b + 10 * c + d,
        i2 = 1000 * d + 100 * a + 10 * b + c,
        i3 = 1000 * c + 100 * d + 10 * a + b,
        i4 = 1000 * b + 100 * c + 10 * d + a;
    if (!bit[i1] && !bit[i2] && !bit[i3] && !bit[i4]) {
      count++;
      bit.set(i1);
      bit.set(i2);
      bit.set(i3);
      bit.set(i4);
    }
  }
  cout << count << endl;
}
