#include<stdio.h> #include<string.h> #define N 100 int map[N][N], vis[N], degree[N]; int n, m, a, b, t = 0, count; void dfs(int u) { vis[u] = 1; count++; for (int i = 1;i <= 51; i++) if (!vis[i] && map[u][i]) { dfs(i); } return; }//深度遍历 int circuit() { for(int i = 1;i <= 51; i++) if(degree[i] % 2 != 0) return 0; return 1; }//判断是否连通 void euler(int u) { for(int i = 1;i < 51; i++) if(map[u][i]) { map[u][i]--; map[i][u]--; euler(i); printf("%d %d\n", i, u); } return; }//递归,将已经递归到头的那个数输出 int main(){ scanf("%d", &n); while(n--){ int k = 0, cnt = 0, flag = 0; scanf("%d", &m); memset(map, 0, sizeof(map)); memset(vis, 0, sizeof(vis)); memset(degree, 0, sizeof(degree)); for (int i = 0;i < m; i++) { scanf("%d %d", &a, &b); map[a][b]++; map[b][a]++;//记录边数 degree[a]++; degree[b]++;//记录每一个的度数 } for (int j = 0;j < 51; j++) { if(degree[j]) { cnt++; k = j; } } printf("Case #%d\n", ++t); if (!circuit()) { flag = 1; printf("some beads may be lost\n"); } count = 0; if (!flag) { dfs(k); if (count != cnt) printf("some beads may be lost\n"); else euler(k); } if (n != 0) printf("\n"); } return 0; }