一个简单深搜
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <stack>
#include <algorithm>
//#include "myAlgorithm.h"
#define MAX 25
#define INF (1e8 + 5)
#define eps 1e-8
#define Rep(s, e) for( int i = s; i <= e; i++)
#define Cep(e, s) for( int i = e; i >= s; i --)
using namespace std;
int m;
int k, adj[MAX][MAX], ans[MAX];
int v[MAX];
void find(int node, int num){
if(num >= 20){
Rep(0, 2){
if(adj[node][i] == m){
cout<<++k<<": ";
for(int j = 1; j <20; j++)cout<<ans[j]<<" ";
cout<<node<<" "<<m<<endl;
break;
}
}
return ;
}
v[node] = 1;
ans[num] = node;
Rep(0, 2){
int next = adj[node][i];
if(!v[next]){
find(next, num + 1);
}
}
v[node] = 0;
return ;
}
int main()
{
//freopen("in.tx0t", "w", stdout);
Rep(1, 20){
for(int j = 0; j < 3; j++){
cin>>adj[i][j];
}sort(adj[i], adj[i] + 3);
}
while(cin>>m,m){
k = 0;
find(m, 1);
}
return 0;
}
/*
*/