#include <bits/stdc++.h>   using namespace std;   const int ALPHA = 26 + 1;   struct Trie {     Trie() { nodes.resize(2); }     struct Node {       Node() { memset(next, 0, sizeof(next)); }       int next[ALPHA];       int finish = -1;     };     int alloc() {       nodes.push_back(Node());       return nodes.size() - 1;     }     void addWord(const string& s, int id) {       int v = root;       for (char c : s) {         c = tolower(c) -  a ;         if (!nodes[v].next[c]) {           int x = alloc();           nodes[v].next[c] = x;         }         v = nodes[v].next[c];       }       nodes[v].finish = id;     }     vector<Node> nodes;     const int root = 1;   };   int n;   string ciph;   int m;   Trie trie;   vector<int> solved;   vector<int> toTake;   bool solve(int pos) {     if (pos == n) {       return true;     }     if (solved[pos] == -1) {       solved[pos] = false;       int v = trie.root;       int i = pos;       while (i < ciph.length() && trie.nodes[v].next[ciph[i] -  a ]) {         v = trie.nodes[v].next[ciph[i] -  a ];         ++i;         if (trie.nodes[v].finish != -1) {           if (solve(i)) {             solved[pos] = true;             toTake[pos] = trie.nodes[v].finish;           }         }       }     }     return solved[pos];   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     solved.resize(n, -1);     toTake.resize(n, -1);     cin >> ciph;     cin >> m;     vector<string> words(m);     for (int i = 0; i < m; ++i) {       cin >> words[i];       trie.addWord(words[i], i);     }     reverse(ciph.begin(), ciph.end());     solve(0);     vector<int> ans;     if (solved[0] == 1) {       int pos = 0;       while (pos != n) {         int id = toTake[pos];         ans.push_back(id);         pos += words[id].length();       }     } else {       assert(false);     }     reverse(ans.begin(), ans.end());     for (int i = 0; i < ans.size(); ++i) {       if (i != 0) {         cout <<    ;       }       cout << words[ans[i]];     }     cout << endl;     return 0;   }   