```#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int arr[7][6];
vector<int> vec, ans;
int indexes[7][7];
int rots[7];
inline int getx0(int idx) {
return arr[vec[0]][( indexes[vec[0]][1]+idx)%6];
}
inline int getx(int idx, int idx2, int orig) {
int x =  arr[idx][(   (6+indexes[idx][getx0(orig-1)]-(orig+2)%6)%6   +idx2)%6];
return x;
}
inline bool f() {
for(int i=1; i<=5; i++) {
if(getx(vec[i],(i+1)%6,i)  != getx(vec[i+1],(i+4)%6, i+1) ) {
return false;
}
}
if(getx(vec[6],1,6) != getx(vec[1], 4, 1)) {
return false;
}

return true;
}
int main(void) {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n; cin >> n;
for(int i=0; i<n; i++) {
vec.clear();
vec =  {0, 1, 2, 3, 4, 5, 6};//{0, 6, 4, 5, 3, 1, 2};
for(int j=0; j<7; j++) {
for(int k=0; k<6; k++) {
cin >> arr[j][k];
indexes[j][ arr[j][k] ] = k;
}
}

cout << "Case " << i+1 << ":";
bool done = false;
do {
done = f();
} while(!done && next_permutation(vec.begin(), vec.end()));
if(done) {
for(int x:vec) cout << " " << x;
cout << endl;
} else {
cout << " No solution" << endl;
}
}
return 0;
}

```