#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;
 
enum { TOP = 0, BOTTOM, FRONT, BACK, LEFT, RIGHT };
enum { WEST = 0, NORTH, EAST, SOUTH };
 
class Dice
{
public:
  int num[6];
   
  int getTop()    { return num[TOP];    }
  int getBottom() { return num[BOTTOM]; }
  int getFront()  { return num[FRONT];  }
  int getBack()   { return num[BACK];   }
  int getLeft()   { return num[LEFT];   }
  int getRight()  { return num[RIGHT];  }
   
  void roll(int dir)
  {
    int tmp;
    switch(dir) {
    case EAST:
      tmp = num[RIGHT];
      num[RIGHT] = num[TOP];
      num[TOP] = num[LEFT];
      num[LEFT] = num[BOTTOM];
      num[BOTTOM] = tmp;
      break;
       
    case WEST:
      tmp = num[LEFT];
      num[LEFT] = num[TOP];
      num[TOP] = num[RIGHT];
      num[RIGHT] = num[BOTTOM];
      num[BOTTOM] = tmp;
      break;
       
    case NORTH:
      tmp = num[BOTTOM];
      num[BOTTOM] = num[FRONT];
      num[FRONT] = num[TOP];
      num[TOP] = num[BACK];
      num[BACK] = tmp;
      break;
       
    case SOUTH:
      tmp = num[BOTTOM];
      num[BOTTOM] = num[BACK];
      num[BACK] = num[TOP];
      num[TOP] = num[FRONT];
      num[FRONT] = tmp;
      break;
       
    }
     
  }
   
public:
  
  Dice() {
  }
  
  Dice(int t, int f)
  {
    num[TOP] = t; num[BOTTOM] = 7-t;
    num[FRONT] = f; num[BACK] = 7-f;
     
    switch(num[TOP])
      {
      case 1:
        switch(num[FRONT]) {
        case 3: num[LEFT] = 2; break;
        case 5: num[LEFT] = 3; break;
        case 4: num[LEFT] = 5; break;
        case 2: num[LEFT] = 4; break;
        }
        break;
      case 2:
        switch(num[FRONT]) {
        case 1: num[LEFT] = 3; break;
        case 3: num[LEFT] = 6; break;
        case 4: num[LEFT] = 1; break;
        case 6: num[LEFT] = 4; break;
        }
        break;
      case 3:
        switch(num[FRONT]) {
        case 1: num[LEFT] = 5; break;
        case 2: num[LEFT] = 1; break;
        case 6: num[LEFT] = 2; break;
        case 5: num[LEFT] = 6; break;
        }
        break;
      case 4:
        switch(num[FRONT]) {
        case 1: num[LEFT] = 2; break;
        case 2: num[LEFT] = 6; break;
        case 5: num[LEFT] = 1; break;
        case 6: num[LEFT] = 5; break;
        }
        break;
      case 5:
        switch(num[FRONT]) {
        case 1: num[LEFT] = 4; break;
        case 3: num[LEFT] = 1; break;
        case 4: num[LEFT] = 6; break;
        case 6: num[LEFT] = 3; break;
        }
        break;
      case 6:
        switch(num[FRONT]) {
        case 2: num[LEFT] = 3; break;
        case 3: num[LEFT] = 5; break;
        case 4: num[LEFT] = 2; break;
        case 5: num[LEFT] = 4; break;
        }
        break;
      }
    num[RIGHT] = 7-num[LEFT];
  }

  bool operator == (Dice rhs) const {
    for(int i=0; i<4; i++) {
      for(int j=0; j<4; j++) {
        rhs.roll(NORTH);
        rhs.roll(WEST);
        for(int k=0; k<6; k++) if(num[k]!=rhs.num[k]) continue;
        return true;
      }
    }
    return false;
  }
};

string cols[]={"Red", "Yellow", "Blue", "Magenta", "Green", "Cyan"};
map<string, int> mp;

int main() {
  
  for(int i=0; i<6; i++) mp[cols[i]] = i;
  int N;
  while(cin >> N && N) {
    vector<Dice> d;
    for(int i=0; i<N; i++) {
      string s; int t, f;
      cin >> s; t = mp[s];
      cin >> s; f = mp[s];
      d.push_back(Dice(t, f));
      for(int j=2; j<6; j++) {
        string s; cin >> s;
      }
    }
    
    int cnt = 0;
    bool update = true;
    while(update) {
      update = false;
      for(int i=0; i<d.size(); i++) {
        for(int j=i+1; j<d.size(); j++) {
          if(d[i] == d[j]) {
            d.erase(d.begin()+i); update = true; goto NEXT;
          }
        }
      }
    NEXT:;
    }
    cout << d.size() << endl;
  }
  
  return 0;
}