#include <bits/stdc++.h>
using namespace std;
map<string, int> m;
int main() {
  int n, ans = 0;
  cin >> n;
  while (n--) {
    char a, b, c, d;
    string s, s1, s2, x = "";
    cin >> s1 >> s2;
    if (n) cin >> s;
    a = s1[0];
    b = s1[1];
    c = s2[0];
    d = s2[1];
    x = a;
    x += b;
    x += d;
    x += c;
    if (!m[x]) {
      x = b;
      x += d;
      x += c;
      x += a;
      if (!m[x]) {
        x = d;
        x += c;
        x += a;
        x += b;
        if (!m[x]) {
          x = c;
          x += a;
          x += b;
          x += d;
          if (!m[x]) {
            m[x]++;
            ans++;
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
