#include #include #include #include #include #include #include #include #include using namespace std; ifstream fin("dice.txt"); #define cin fin enum dindex { TOP = 0, FORWARD, RIGHT, LEFT, BACKWARD, BOTTOM, DICE_MAX }; struct dice { int id; int n[DICE_MAX]; dice(int id = -1) : id(id) { for(int i = 0; i < DICE_MAX; i++) n[i] = -1; } }; const int rot_x[] = {BACKWARD, TOP, RIGHT, LEFT, BOTTOM, FORWARD}; const int rot_y[] = {TOP, LEFT, FORWARD, BACKWARD, RIGHT, BOTTOM}; const int rot_z[] = {LEFT, FORWARD, TOP, BOTTOM, BACKWARD, RIGHT}; dice rot(const dice& d, const int* r) { dice nd(d.id); for(int i = 0; i < DICE_MAX; i++) nd.n[i] = d.n[r[i]]; return nd; } void make_top(dice& d, int req) { int where; for(where = TOP; where < DICE_MAX; where++) if(d.n[where] == req) break; assert(where < DICE_MAX); switch(where) { case FORWARD: d = rot(d, rot_x); d = rot(d, rot_x); case BACKWARD: d = rot(d, rot_x); break; case RIGHT: d = rot(d, rot_z); d = rot(d, rot_z); case LEFT: d = rot(d, rot_z); break; case BOTTOM: d = rot(d, rot_x); d = rot(d, rot_x); case TOP: break; } assert(d.n[TOP] == req); } bool operator < (const dice& a, const dice& b) { assert(a.id != b.id); return a.id < b.id; } #define BIT(x, ofs) (1UL << (ofs) + (x) - 1) static inline unsigned int conv_dice(const dice& d) { return BIT(d.n[TOP], 18) | BIT(d.n[FORWARD], 12) | BIT(d.n[BOTTOM], 6) | BIT(d.n[BACKWARD], 0); } static inline bool check(const vector& flags) { unsigned int f = 0UL; for(int i = 0; i < flags.size(); i++) f |= flags[i]; return f == 0xFFFFFFUL; } int main() { if(!fin) return -1; int ncase; cin >> ncase; while(ncase--) { vector d; d.clear(); for(int i = 0; i < 6; i++) { d.push_back(dice(i)); for(int j = 0; j < DICE_MAX; j++) cin >> d[i].n[j]; } unsigned long result = 0; do { vector cd = d; { unsigned int flags = 0UL; for(int j = 0; j < cd.size(); j++) { make_top(cd[j], j + 1); flags |= BIT(cd[j].n[BOTTOM], 0); } if(flags != 0x3F) goto next_round; } /*for(int j = 0; j < cd.size(); j++) cout << cd[j].id; cout << endl;*/ for(int i = 0; i < (1 << d.size() * 2); i++) { /*for(int j = 0; j < cd.size(); j++) cout << cd[j].id; cout << ", " << i << endl;*/ unsigned int flags = 0UL; for(int j = 0; j < cd.size(); j++) flags |= conv_dice(cd[j]); char buffer[32]; /*sprintf(buffer, "0x%08lX", flags); cout << buffer << endl;*/ if(flags == 0x00FFFFFFUL) { //for(int j = 0; j < cd.size(); j++) cout << cd[j].id; //cout << ", " << i << endl; result++; } for(int j = 0; j < cd.size(); j++) { cd[j] = rot(cd[j], rot_y); if(((i >> j * 2) & 3) != 3) break; } } next_round: ; } while(next_permutation(d.begin(), d.end())); assert((result & 7) == 0); cout << (result >> 3) << endl; } return 0; }