#include #include #include #include #include using namespace std; #define min(a,b) ((a)<(b) (a):(b)) #define INF 0x3f3f3f3f const int N = 105; int t; string start, end; char g[105][105]; map dp; map z; int dfs(string start) { if (dp.count(start)) return dp[start]; dp[start] = 0; if (start == end) return dp[start] = 1; for (int i = 0; i < start.size() - 1; i++) { string tmp = ""; tmp += g[start[i]][start[i + 1]]; string s = start; if (dfs(s.replace(i, 2, tmp))) { z[start] = s; return dp[start] = 1; } } return dp[start]; } void print(string start) { cout << start << endl; if (start == end) return; print(z[start]); } int main() { g['a']['a'] = g['a']['b'] = g['b']['b'] = 'b'; g['a']['c'] = g['b']['c'] = g['c']['a'] = 'a'; g['b']['a'] = g['c']['b'] = g['c']['c'] = 'c'; scanf("%d", &t); while (t--) { z.clear(); dp.clear(); cin > > start >> end; if (start.size() < end.size()) { printf("None exist!\n"); continue; } if (dfs(start)) print(start); else printf("None exist!\n"); if (t) printf("\n"); } return 0; }