#include<algorithm>
#include<iostream>
#include<string>
#include<set>
using namespace std;
string a, b, c, d, e, f;
int n;
int main(){
  while(cin >> n, n){
    set<int> num;
    for(int i = 0;i < n;i++){
      cin >> a >> b >> c >> d >> e >> f;
      int p = (int)(b[0] + e[0]) * (int)(c[0] + d[0]) * (int)(a[0] + f[0]);
      if(((a<f) + (b<d) + (c<f)) % 3)p *= -1;
      num.insert(p);
    }
    cout << n - num.size() << endl;
  }
  return 0;
}