#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
using std::string;
 
static struct IO {
	char tmp[1 << 10];
 
	// fast input routines
	char cur;
 
//#define nextChar() (cur = getc_unlocked(stdin))
//#define peekChar() (cur)
	inline char nextChar() { return cur = getc_unlocked(stdin); }
	inline char peekChar() { return cur; }
 
	inline operator bool() { return peekChar(); }
	inline static bool isBlank(char c) { return (c < '-' && c); }
	inline bool skipBlanks() { while (isBlank(nextChar())); return peekChar() != 0; }
 
	inline IO& operator >> (char & c) { c = nextChar(); return *this; }
 
	inline IO& operator >> (char * buf) {
		if (skipBlanks()) {
			if (peekChar()) {
				*(buf++) = peekChar();
				while (!isBlank(nextChar())) *(buf++) = peekChar();
			} *(buf++) = 0; } return *this; }
 
	inline IO& operator >> (string & s) {
		if (skipBlanks()) {	s.clear(); s += peekChar();
			while (!isBlank(nextChar())) s += peekChar(); }
		return *this; }
 
	inline IO& operator >> (double & d) { if ((*this) >> tmp) sscanf(tmp, "%lf", &d); return *this;	}
 
#define defineInFor(intType) \
	inline IO& operator >>(intType & n) { \
		if (skipBlanks()) { \
			int sign = +1; \
			if (peekChar() == '-') { \
				sign = -1; \
				n = nextChar() - '0'; \
			} else \
				n = peekChar() - '0'; \
			while (!isBlank(nextChar())) { \
				n += n + (n << 3) + peekChar() - 48; \
			} \
			n *= sign; \
		} \
		return *this; \
	}
 
defineInFor(int)
defineInFor(unsigned int)
defineInFor(long long)
 
	// fast output routines
 
//#define putChar(c) putc_unlocked((c), stdout)
	inline void putChar(char c) { putc_unlocked(c, stdout); }
	inline IO& operator << (char c) { putChar(c); return *this; }
	inline IO& operator << (const char * s) { while (*s) putChar(*s++); return *this; }
 
	inline IO& operator << (const string & s) { for (int i = 0; i < (int)s.size(); ++i) putChar(s[i]); return *this; }
 
	char * toString(double d) { sprintf(tmp, "%lf%c", d, '\0'); return tmp; }
	inline IO& operator << (double d) { return (*this) << toString(d); }
 
 
#define defineOutFor(intType) \
	inline char * toString(intType n) { \
		char * p = (tmp + 30); \
		if (n) { \
			bool isNeg = 0; \
			if (n < 0) isNeg = 1, n = -n; \
			while (n) \
				*--p = (n % 10) + '0', n /= 10; \
			if (isNeg) *--p = '-'; \
		} else *--p = '0'; \
		return p; \
	} \
	inline IO& operator << (intType n) { return (*this) << toString(n); }
 
defineOutFor(int)
defineOutFor(long long)
 
#define endl ('\n')
#define cout __io__
#define cin __io__
} __io__;
 

int rotation[8];
int turn[7][8];
int pieces[7][6];
int xx[8];
int main(){
    ios::sync_with_stdio(0);
    int t; cin>>t;
    for (int ca=1;ca<=t;ca++){
        cout<<"Case "<<ca<<":"; 
        for (int i=0;i<7;i++) for (int j=0;j<6;j++) cin>>pieces[i][j];
        for (int i=0;i<7;i++) for (int j=1;j<=6;j++){
            int x;
            for (x=0;x<6;x++) if (pieces[i][x]==j) break;
            turn[i][j]=x;
        }
        vector<int> v={0,1,2,3,4,5,6};
        bool solved=false;
        do{
            bool good=true; 
            for (int i=1;i<7;i++) rotation[i]=turn[v[i]][pieces[v[0]][(turn[v[0]][1]+i-1)%6]];
            for (int i=1;i<6;i++) {
                if (pieces[v[i]][(rotation[i]+5)%6]!=pieces[v[i+1]][(rotation[i+1]+1)%6]) {
                    good=false; break;
                }
            }
            if (!good) continue;
            if (pieces[v[6]][(rotation[6]+5)%6]!=pieces[v[1]][(rotation[1]+1)%6]) good=false;
            if (good){
                for(int x:v) cout<<" "<<x; cout<<endl;
                solved=true; break;
            }
        } while ((next_permutation(v.begin(),v.end()))&&(!solved));
        if (!solved) cout<<" No solution"<<endl;
    }
    return 0;
}