text: /*=============================================================================
  #  Author:          Teerapat Jenrungrot - https://github.com/mjenrungrot/
  #  FileName:        10150.cc
  #  Description:     UVa Online Judge - 10150
  =============================================================================*/
  #include <bits/stdc++.h>
  #pragma GCC optimizer("Ofast")
  #pragma GCC target("avx2")
  using namespace std;
  
  typedef pair<int, int> ii;
  typedef pair<long long, long long> ll;
  typedef pair<double, double> dd;
  typedef tuple<int, int, int> iii;
  typedef tuple<long long, long long, long long> lll;
  typedef tuple<double, double, double> ddd;
  typedef vector<string> vs;
  typedef vector<int> vi;
  typedef vector<vector<int>> vvi;
  typedef vector<long long> vl;
  typedef vector<vector<long long>> vvl;
  typedef vector<double> vd;
  typedef vector<vector<double>> vvd;
  typedef vector<ii> vii;
  typedef vector<ll> vll;
  typedef vector<dd> vdd;
  
  // Debug Snippets
  
  void __print(int x) { cerr << x; }
  void __print(long x) { cerr << x; }
  void __print(long long x) { cerr << x; }
  void __print(unsigned x) { cerr << x; }
  void __print(unsigned long x) { cerr << x; }
  void __print(unsigned long long x) { cerr << x; }
  void __print(float x) { cerr << x; }
  void __print(double x) { cerr << x; }
  void __print(long double x) { cerr << x; }
  void __print(char x) { cerr << '\'' << x << '\''; }
  void __print(const char* x) { cerr << '\"' << x << '\"'; }
  void __print(const string& x) { cerr << '\"' << x << '\"'; }
  void __print(bool x) { cerr << (x ? "true" : "false"); }
  
  template <typename T, typename V>
  void __print(const pair<T, V>& x) {
      cerr << '{';
      __print(x.first);
      cerr << ',';
      __print(x.second);
      cerr << '}';
  }
  template <typename T>
  void __print(const T& x) {
      int f = 0;
      cerr << '{';
      for (auto& i : x) cerr << (f++ ? "," : ""), __print(i);
      cerr << "}";
  }
  void _print() { cerr << "]\n"; }
  template <typename T, typename... V>
  void _print(T t, V... v) {
      __print(t);
      if (sizeof...(v)) cerr << ", ";
      _print(v...);
  }
  
  #define debug(x...)               \
      cerr << "[" << #x << "] = ["; \
      _print(x)
  
  template <class Ch, class Tr, class Container>
  basic_ostream<Ch, Tr>& operator<<(basic_ostream<Ch, Tr>& os,
                                    Container const& x) {
      os << "{ ";
      for (auto& y : x) os << y << " ";
      return os << "}";
  }
  
  template <class X, class Y>
  ostream& operator<<(ostream& os, pair<X, Y> const& p) {
      return os << "[ " << p.first << ", " << p.second << "]";
  }
  
  // End Debug Snippets
  
  vs split(string line, regex re) {
      vs output;
      sregex_token_iterator it(line.begin(), line.end(), re, -1), it_end;
      while (it != it_end) {
          output.push_back(it->str());
          it++;
      }
      return output;
  }
  
  const int INF_INT = 1e9 + 7;
  const long long INF_LL = 1e18;
  const int MAXN = 30000;
  
  map<string, int> to_idx;
  vs words;
  vi V[MAXN];
  
  void print_sol(int node, vi& parent) {
      if (parent[node] == -1) {
          cout << words[node] << endl;
          return;
      } else {
          print_sol(parent[node], parent);
          cout << words[node] << endl;
      }
  }
  
  int main() {
      ios::sync_with_stdio(false);
      cin.tie(0);
  
      string line;
      while (getline(cin, line)) {
          if (line == "") break;
          to_idx[line] = words.size();
          words.push_back(line);
      }
  
      for (int idx = 0; idx < words.size(); idx++) {
          string word = words[idx];
          for (int i = 0; i < word.length(); i++) {
              char original = word[i];
              for (char newch = 'a'; newch <= 'z'; newch++) {
                  if (newch == original) continue;
                  word[i] = newch;
                  if (to_idx.count(word)) {
                      V[idx].push_back(to_idx[word]);
                  }
              }
              word[i] = original;
          }
      }
  
      bool newline = false;
      while (getline(cin, line)) {
          istringstream iss(line);
          string source, target;
          iss >> source >> target;
  
          if (newline) cout << endl;
          newline = true;
  
          if (not to_idx.count(source) or not to_idx.count(target)) {
              cout << "No solution." << endl;
              continue;
          }
  
          int st = to_idx[source];
          int en = to_idx[target];
  
          vi visited(MAXN);
          vi parent(MAXN, -1);
  
          queue<ii> Q;
          Q.push({st, -1});
  
          bool found = false;
          while (not Q.empty()) {
              auto uu = Q.front();
              auto u = uu.first;
              auto p = uu.second;
              Q.pop();
  
              if (visited[u]) continue;
              visited[u] = true;
              parent[u] = p;
  
              if (u == en) {
                  found = true;
                  break;
              }
  
              for (auto& v : V[u]) {
                  if (not visited[v]) {
                      Q.push({v, u});
                  }
              }
          }
          if (not found)
              cout << "No solution." << endl;
          else
              print_sol(en, parent);
      }
  
      return 0;
  }