#include <cstdio>

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

int n, r;

int dep(int a, int b) {
    if (a < b) return dep(b, a);
    return b ? a / b + dep(b, a % b) : 0;
}

int gao(int a, int b) {
    if (a < b) return gao(b, a);
    if (b == 1) return a / b - 1;
    return a / b - 1 + gao(b, a % b);
}

int dfs(int a, int b) {
    if (b == 1) {
        printf("T");
        for (int i = 1; i < a; ++i) {
            printf("B");
        }
        return 0;
    }
    int x = dfs(b, a % b);
    for (int i = 0; i < a/b; ++i) {
        printf(x ? "B" : "T");
    }
    return !x;
}

int main() {
    scanf("%d%d", &n, &r);
    int ans = n+1, k;
    for (int i = 1; i < r; ++i) {
//      printf("%d %d %d", i, gcd(r, i), dep(r, i));
        if (gcd(r, i) == 1 && dep(r, i) == n) {
            int tmp = gao(r, i);
//          printf(" %d", tmp);
            if (tmp < ans) {
                ans = tmp;
                k = i;
            }
        }
//      puts("");
    }
    if (ans > n) {
        puts("IMPOSSIBLE");
    } else {
        printf("%d\n", ans-1);
        dfs(r, k);
        puts("");
    }
}


/*
 * Problem:
 * Author: Leo Yu
 * Time:
 * State: Coding
 * Memo:
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>

using namespace std;

typedef long long LL;

inline int read()
{
	int x = 0; char ch = getchar(); bool positive = 1;
	for (; ch < '0' || ch > '9'; ch = getchar())	if (ch == '-')	positive = 0;
	for (; ch >= '0' && ch <= '9'; ch = getchar())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}

int N, R, ans[1000006];

inline bool check(int a, int b, int now)
{
	for (int i = now + 1; i <= N; ++ i)
	{
		int tmp = a; a = b; b = tmp + b;
		if (b >= R)	return 1;
	}
	return b >= R;
}

int main()
{
	//freopen("a.in", "r", stdin);
	//freopen("a.out", "w", stdout);

	N = read(); R = read();
	int a = 1, b = 1;
	ans[1] = 0;
	int last = 0;
	int cnt = 0;
	for (int i = 2; i <= N; ++ i)
	{
		if (a != b && i < N && check(a, a + b, i))
		{
			if (last)	ans[i] = 1, last = 1;	else	ans[i] = 0, last = 0;
			b = a + b;
			++ cnt;
		}
		else
		{
			if (!last)	ans[i] = 1, last = 1;	else	ans[i] = 0, last = 0;
			int tmp = a; a = b; b = tmp + b;
		}
	}
	if (b != R)
	{
		printf("IMPOSSIBLE\n");
		return 0;
	}
	printf("%d\n", cnt);
	for (int i = 1; i <= N; ++ i)
		if (!ans[i])	printf("T");
		else	printf("B");
	printf("\n");

	return 0;
}


/*
 * Problem:
 * Author: Leo Yu
 * Time:
 * State: Coding
 * Memo:
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>

using namespace std;

typedef long long LL;

char s[2] = {'T', 'B'};

inline int read()
{
	int x = 0; char ch = getchar(); bool positive = 1;
	for (; ch < '0' || ch > '9'; ch = getchar())	if (ch == '-')	positive = 0;
	for (; ch >= '0' && ch <= '9'; ch = getchar())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}

int N, R, S;

int work(int x, int y)
{
	int ans = 0;
	if (x == 0 && y == 1)	return ans;
	if (x == 0)return 1 << 30;
	ans = work(y % x, x) + y / x - 1;
	S += y / x;
	return ans;
}

int Print(int x, int y)
{
	if (x == 0 && y == 1)return 0;
	int k = Print(y % x, x) ^ 1;
	if (y % x != 0)
	{
		for (int i = 1; i <= y / x; ++i)	printf("%c", s[k]);
	}
	else
	{
		printf("T");
		for (int i = 1; i < y / x; ++i)	printf("%c", s[k]);
	}
	return k;
}

int main()
{
	//freopen("a.in", "r", stdin);
	//freopen("a.out", "w", stdout);

	N = read(); R = read();
	int ans = 999999999, p;
	if (N == 1 && R == 1)
	{
		printf("0\n");
		printf("T\n");
		return 0;
	}
	for (int i = 1; i < R; ++i)
	{
		S = 0;
		int now = work(i, R);
		if (S != N)	continue;
		if (now < ans)
		{
			ans = now; p = i;
		}
	}
	if (ans == 999999999)	printf("IMPOSSIBLE\n");
	else
	{
		printf("%d\n", ans - 1);
		Print(p, R);
		printf("\n");
	}

	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const int inf=1<<29;
int func(int a, int b)
{
	if (a==0 && b==1) return 0;
	if (a==0 || b==0) return inf;
	if (a>=b) return 1+func(a-b,b);
	return 1+func(a,b-a);
}
string func2(int a, int b)
{
	if (a==0 && b==1) return "";
	if (a>=b) return "T"+func2(a-b,b);
	return "B"+func2(a,b-a);
}
int func3(const string& s)
{
	int n=s.size();
	int res=0;
	for (int i=0;i<n;++i) res+=(s[i]!=(i%2?'B':'T'));
	return res;
}
int main()
{
	int n, r;
	const string impossible="IMPOSSIBLE";
	while (cin>>n>>r) {
		string res=impossible;
		int k=inf;
		int bestscore=inf;
		for (int i=0;i<=r;++i) {
			if (func(i,r)==n) {
				string s=func2(i,r);
				reverse(s.begin(), s.end());
				int score=func3(s);
				if (score<bestscore) { res=s; bestscore=score; }
			}
			if (i&&func(r,i)==n) {
				string s=func2(r,i);
				reverse(s.begin(), s.end());
				int score=func3(s);
				if (score<bestscore) { res=s; bestscore=score; }
			}
		}
		if (bestscore<inf) cout<<bestscore<<endl;
		cout<<res<<endl;
	}
	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const int inf=1<<29;
int func(int a, int b)
{
	if (a==0 && b==1) return 0;
	if (a==0 || b==0) return inf;
	if (a==1 && b>1) return b-1+func(1,1);
	if (a>=b) return a/b+func(a%b,b);
	return b/a+func(a,b%a);
}
string func2(int a, int b)
{
	if (a==0 && b==1) return "";
	if (a==1 && b>1) return string(b-1,'B')+func2(1,1);
	if (a>=b) return string(a/b,'T')+func2(a%b,b);
	return string(b/a,'B')+func2(a,b%a);
}
int func3(const string& s)
{
	int n=s.size();
	int res=0;
	for (int i=0;i<n-1;++i) res+=(s[i]==s[i+1]);
	return res;
}
int main()
{
	int n, r;
	while (cin>>n>>r) {
		string res;
		int k=inf;
		int bestscore=inf;
		for (int i=0;i<=r;++i) {
			if (func(i,r)==n) {
				string s=func2(i,r);
				int score=func3(s);
				if (score<bestscore) { res=s; bestscore=score; }
			}
			if (i&&func(r,i)==n) {
				string s=func2(r,i);
				int score=func3(s);
				if (score<bestscore) { res=s; bestscore=score; }
			}
		}
		if (bestscore<inf) {
			reverse(res.begin(), res.end());
			cout<<bestscore<<endl<<res<<endl;
		}
		else
			cout<<"IMPOSSIBLE"<<endl;
	}
	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const int inf=1<<29;
int func(int a, int b)
{
	if (a==0 && b==1) return 0;
	if (a==0 || b==0) return inf;
	if (a>=b) return 1+func(a-b,b);
	return 1+func(a,b-a);
}
string func2(int a, int b)
{
	if (a==0 && b==1) return "";
	if (a>=b) return "T"+func2(a-b,b);
	return "B"+func2(a,b-a);
}
int func3(const string& s)
{
	if (s[0]=='B') return inf;
	int n=s.size();
	int res=0;
	for (int i=0;i<n-1;++i) res+=(s[i]==s[i+1]);
	return res;
}
int main()
{
	int n, r;
	const string impossible="IMPOSSIBLE";
	while (cin>>n>>r) {
		string res=impossible;
		int k=inf;
		int bestscore=inf;
		for (int i=0;i<=r;++i) {
			if (func(i,r)==n) {
				string s=func2(i,r);
				reverse(s.begin(), s.end());
				int score=func3(s);
				if (score<bestscore) { res=s; bestscore=score; }
			}
			if (i&&func(r,i)==n) {
				string s=func2(r,i);
				reverse(s.begin(), s.end());
				int score=func3(s);
				if (score<bestscore) { res=s; bestscore=score; }
			}
		}
		if (bestscore<inf) cout<<bestscore<<endl;
		cout<<res<<endl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <map>

#define MAXN 1000000
#pragma pack(1)

class Vertex
{
public:
	std::map<char, int> next;
	std::map<char, int> go;
	bool leaf;
	int p;
	char pch;
	int link;
	int id;

	int GetNext(char c)
	{
		if(next.count(c)) return next[c];
		return -1;
	}

	int GetGo(char c)
	{
		if(go.count(c)) return go[c];
		return -1;
	}
};

std::vector<Vertex> t(1);
int sz;

void Init()
{
	t[0].p = t[0].link = -1;
	sz = 1;
}

std::vector<std::string> words;

void AddString(const std::string &s, int _id)
{
	int v = 0;
	for(size_t i = 0; i < s.size(); i++)
	{
		char c = s[i] - 'a';
		if(t[v].GetNext(c) == -1)
		{
		    t.push_back(Vertex());
			t[sz].link = -1;
			t[sz].p = v;
			t[sz].pch = c;
			t[v].next[c] = sz;
			sz++;
		}
		v = t[v].next[c];
	}
	t[v].leaf = true;
	words.push_back(s);
	t[v].id = _id;
}

int Go(int v, char c);

int GetLink(int v)
{
	if(t[v].link == -1)
		if(v == 0 || t[v].p == 0)
			t[v].link = 0;
		else
			t[v].link = Go(GetLink(t[v].p), t[v].pch);
	return t[v].link;
}

int Go(int v, char c)
{
	if(t[v].GetGo(c) == -1)
		if(t[v].GetNext(c) != -1)
			t[v].go[c] = t[v].next[c];
		else
			t[v].go[c] = v == 0 ? 0 : Go(GetLink(v), c);
	return t[v].go[c];
}

class Range
{
public:
	int l, id;

	Range() { l = id = 0; }
	Range(int _l, int _id) { l = _l; id = _id; }

	int GetR() const { return l + (int)words[id].size() - 1; }
};

bool RangesComp(Range a, Range b)
{
	return a.GetR() < b.GetR();
}

struct RangeComparator
{
	bool operator()(const Range &a, const Range &b)
	{
		return a.GetR() == b.GetR() ? a.l < b.l : a.GetR() < b.GetR();
	}
};

std::set<Range, RangeComparator> ranges;
void Check(int v, int i)
{
    for(int u = v; u != 0; u = GetLink(u))
	{
        if (t[u].leaf)
		{
			int l = i - (int)words[t[u].id].size();
			ranges.insert(Range(l, t[u].id));
		}
    }
}

void FindAllPos(const std::string& s)
{
    int u = 0;
    for(int i = 0; i < (int)s.size(); i++)
	{
        u = Go(u, s[i] - 'a');
        Check(u, i + 1);
    }
}

int n, dp[10007], pred[10007], g_id;
std::string text;
std::vector<std::string> words_ans;
std::set<std::string> strings;

int ReadInt()
{
	std::string s;
	std::getline(std::cin, s);
	int p = 1, x = 0;
	for(int i = (int)s.size() - 1; i >= 0; i--)
	{
		x += (s[i] - '0') * p;
		p *= 10;
	}
	return x;
}

void GetWord()
{
	std::string word;
	std::getline(std::cin, word);
	words_ans.push_back(word);
	std::transform(word.begin(), word.end(), word.begin(), tolower);
	std::reverse(word.begin(), word.end());
	if(strings.count(word)) { words.push_back(""); words_ans.pop_back(); words_ans.push_back(""); }
	else AddString(word, g_id);

	strings.insert(word);

	g_id++;
}

int main()
{
	std::ios_base::sync_with_stdio(0);

	std::getline(std::cin, text);
	std::getline(std::cin, text);
	n = ReadInt();

	Init();
	for (int i = 0; i < n; i++) GetWord();
	t.shrink_to_fit();
	strings.clear();
	FindAllPos(text);
	t.clear();
	t.shrink_to_fit();

	for(int i = 0; i < 10007; i++) dp[i] = -1;
	for(int i = 0; i < 10007; i++) pred[i] = -1;

	for(auto it = ranges.begin(); it != ranges.end(); it++)
	{
		if(it->l == 0)
		{
			dp[it->GetR()] = it->id;
			pred[it->GetR()] = -1;
			continue;
		}

		int prev = dp[it->l - 1];
		if(prev == -1) continue;

		dp[it->GetR()] = it->id;
		pred[it->GetR()] = it->l - 1;
	}

	int r = text.size() - 1;
	std::vector<int> ans;
	while(r != -1)
	{
		ans.push_back(dp[r]);
		r = pred[r];
	}
	std::reverse(ans.begin(), ans.end());

	for (size_t i = 0; i < ans.size(); i++)
	{
		std::cout << words_ans[ans[i]] << ' ';
	}

	return 0;
}


#include <bits/stdc++.h>

#define _ ios_base::sync_with_stdio(0);cin.tie();
#define what_is(x) cerr << #x << " = " << x << endl;
#define what_is2(x,y) cerr << #x << " = " << x << " | " << #y << " = " << y << endl;
#define what_is_vi(v) for(auto e:v)cout<<e<<" ";cout<<endl;
#define what_is_vpii(v) for(auto e:v)cout<<"{"<<e.first<<","<<e.second<<"} ";cout<<endl;
#define padding(n) for(int i=0;i<(n);i++) cout << " ";

#define PI 3.14159265358979d

#define mp make_pair
#define pb push_back
#define eb emplace_back
//#define mt make_tuple
#define gcd __gcd

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vpii vector<pii>
#define vpci vector<pair<char,int>>
#define vpic vector<pair<int,char>>
#define vi vector<int>
#define vs vector<string>
#define F first
#define S second

#define LLINF 1000000000000LL
#define INF 2000000000
#define MOD 1000000007

#define A 423742419
#define B 204235415

using namespace std;

string words[101010];
map<ll,int> hlist;
int idlist[101010];

int main() {

    int n;
    cin >> n;

    string t;
    cin >> t;
    reverse(t.begin(), t.end());

    int w;
    cin >> w;

    for(int i=1;i<=w;i++) {
        string word;
        cin >> word;

        words[i] = word;

        transform(word.begin(), word.end(), word.begin(), ::tolower);

        ll h=0;
        for(int j=0;j<word.length();j++) {
            h *= A;
            h += word[j];
            h %= B;
        }

        hlist[h] = i;
    }

    for(int i=0;i<n;i++) {
        if(idlist[i]) continue;

        ll h=0;
        for(int l=1;l<=1000;l++) {
            if(i+l>n) break;

            h *= A;
            h += t[i+l-1];
            h %= B;

            if(hlist.count(h)) {
                idlist[i+l-1] = hlist[h];
            }
        }
    }

    string final="";
    int i=n-1;
    while(i>=0) {
        final += words[idlist[i]];
        final += " ";
        i -= words[idlist[i]].length();
    }

    cout << final << endl;
    return 0;
}


#include <bits/stdc++.h>

#define _ ios_base::sync_with_stdio(0);cin.tie();
#define what_is(x) cerr << #x << " = " << x << endl;
#define what_is2(x,y) cerr << #x << " = " << x << " | " << #y << " = " << y << endl;
#define what_is_vi(v) for(auto e:v)cout<<e<<" ";cout<<endl;
#define what_is_vpii(v) for(auto e:v)cout<<"{"<<e.first<<","<<e.second<<"} ";cout<<endl;
#define padding(n) for(int i=0;i<(n);i++) cout << " ";

#define PI 3.14159265358979d

#define mp make_pair
#define pb push_back
#define eb emplace_back
//#define mt make_tuple
#define gcd __gcd

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vpii vector<pii>
#define vpci vector<pair<char,int>>
#define vpic vector<pair<int,char>>
#define vi vector<int>
#define vs vector<string>
#define F first
#define S second

#define LLINF 1000000000000LL
#define INF 2000000000
#define MOD 1000000007

#define A 423742419
#define B 204235415

using namespace std;

string words[101010];
unordered_map<ll,int> hlist;
int idlist[101010];

int main() {

    int n;
    cin >> n;

    string t;
    cin >> t;
    reverse(t.begin(), t.end());

    int w;
    cin >> w;

   // set<pair<ll,int>> hlist;

    for(int i=1;i<=w;i++) {
        string word;
        cin >> word;

        words[i] = word;

        transform(word.begin(), word.end(), word.begin(), ::tolower);

        ll h=0;
        for(int j=0;j<word.length();j++) {
            h *= A;
            h += word[j];
            h %= B;
        }

        //hlist.insert({h,i});
        hlist[h] = i;
    }

    for(int i=0;i<n;i++) {
        if(i>0&&!idlist[i]) continue;
        ll h=0;
        for(int l=1;l<=1000;l++) {
            if(i+l>n) break;

            h *= A;
            h += t[i+l-1];
            h %= B;

            if(hlist.count(h)) {
                idlist[i+l] = hlist[h];
            }
        }
    }

    string final="";
    int i=n;
    while(i>0) {
        final += words[idlist[i]];
        final += " ";
        i -= words[idlist[i]].length();
    }

    cout << final << endl;
    return 0;
}


#include <bits/stdc++.h>

#define _ ios_base::sync_with_stdio(0);cin.tie();
#define what_is(x) cerr << #x << " = " << x << endl;
#define what_is2(x,y) cerr << #x << " = " << x << " | " << #y << " = " << y << endl;
#define what_is_vi(v) for(auto e:v)cout<<e<<" ";cout<<endl;
#define what_is_vpii(v) for(auto e:v)cout<<"{"<<e.first<<","<<e.second<<"} ";cout<<endl;
#define padding(n) for(int i=0;i<(n);i++) cout << " ";

#define PI 3.14159265358979d

#define mp make_pair
#define pb push_back
#define eb emplace_back
//#define mt make_tuple
#define gcd __gcd

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vpii vector<pii>
#define vpci vector<pair<char,int>>
#define vpic vector<pair<int,char>>
#define vi vector<int>
#define vs vector<string>
#define F first
#define S second

#define LLINF 1000000000000LL
#define INF 2000000000
#define MOD 1000000007

#define A 423742419
#define B 204235415

using namespace std;

string words[101010];
unordered_map<ll,int> hlist;
int idlist[101010];

int main() {

    int n;
    cin >> n;

    string t;
    cin >> t;
    reverse(t.begin(), t.end());

    int w;
    cin >> w;

    set<pair<ll, int>> hlist;

    for(int i=1;i<=w;i++) {
        string word;
        cin >> word;

        words[i] = word;

        transform(word.begin(), word.end(), word.begin(), ::tolower);

        ll h=0;
        for(int j=0;j<word.length();j++) {
            h *= A;
            h += word[j];
            h %= B;
        }

        hlist.insert({h,i});
    }

    for(int i=0;i<n;i++) {
        if(idlist[i]) continue;

        ll h=0;
        for(int l=1;l<=1000;l++) {
            if(i+l>n) break;

            h *= A;
            h += t[i+l-1];
            h %= B;

            auto it = hlist.lower_bound({h, -1});
            if(it != hlist.end() && it->F == h) {
                idlist[i+l-1] = it->S;
            }
        }
    }

    string final="";
    int i=n-1;
    while(i>=0) {
        final += words[idlist[i]];
        final += " ";
        i -= words[idlist[i]].length();
    }

    cout << final << endl;
    return 0;
}


#include <bits/stdc++.h>

#define _ ios_base::sync_with_stdio(0);cin.tie();
#define what_is(x) cerr << #x << " = " << x << endl;
#define what_is2(x,y) cerr << #x << " = " << x << " | " << #y << " = " << y << endl;
#define what_is_vi(v) for(auto e:v)cout<<e<<" ";cout<<endl;
#define what_is_vpii(v) for(auto e:v)cout<<"{"<<e.first<<","<<e.second<<"} ";cout<<endl;
#define padding(n) for(int i=0;i<(n);i++) cout << " ";

#define PI 3.14159265358979d

#define mp make_pair
#define pb push_back
#define eb emplace_back
//#define mt make_tuple
#define gcd __gcd

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vpii vector<pii>
#define vpci vector<pair<char,int>>
#define vpic vector<pair<int,char>>
#define vi vector<int>
#define vs vector<string>
#define F first
#define S second

#define LLINF 1000000000000LL
#define INF 2000000000
#define MOD 1000000007

#define A 423742419
#define B 204235415

using namespace std;

unordered_map<ll, int> dict;
string words[101010];
ll p[101010], x[101010];

ll h(int a, int b) {
    ll pb = p[b];
    if(a>0) pb -= (p[a-1]*x[b-a+1])%B;
    if(pb<0) pb += B;
    return pb;
}

int n;
vector<int> ids;
bool gf=false;
string final;

void f(int l, int r) {
    if(gf) return;
    if(r>=n) return;
    ll h_lr = h(l,r);
    if(dict.count(h_lr)) {
        int id = dict[h_lr];
        if(r == n-1) {
            final += words[id];
            for(int id_i=ids.size()-1;id_i>=0;id_i--) {
                final += " ";
                final += words[ids[id_i]];
            }
            gf=true;
            return;
        } else {
            ids.pb(id);
            f(r+1,r+1);
            ids.pop_back();
            f(l,r+1);
        }
    } else {
        f(l, r+1);
    }

    return;
}

int main() { _

    cin >> n;
    string t; cin >> t;
    reverse(t.begin(), t.end());

    p[0] = t[0];
    x[0] = 1;
    for(int i=1;i<n;i++) {
        p[i] = (p[i-1]*A+t[i])%B;
        x[i] = (x[i-1]*A)%B;
    }

    int m; cin >> m;
    for(int i=0;i<m;i++) {
        string w; cin >> w;
        words[i] = w;
        std::transform(w.begin(), w.end(), w.begin(), ::tolower);

        ll hw=0;
        for(int j=0;j<w.length();j++) {
            hw = hw*A+w[j];
            hw %= B;
        }

        dict[hw] = i;
    }

    f(0,0);
    cout << final << endl;

    return 0;
}


#include <bits/stdc++.h>

#define _ ios_base::sync_with_stdio(0);cin.tie();
#define what_is(x) cerr << #x << " = " << x << endl;
#define what_is2(x,y) cerr << #x << " = " << x << " | " << #y << " = " << y << endl;
#define what_is_vi(v) for(auto e:v)cout<<e<<" ";cout<<endl;
#define what_is_vpii(v) for(auto e:v)cout<<"{"<<e.first<<","<<e.second<<"} ";cout<<endl;
#define padding(n) for(int i=0;i<(n);i++) cout << " ";

#define PI 3.14159265358979d

#define mp make_pair
#define pb push_back
#define eb emplace_back
//#define mt make_tuple
#define gcd __gcd

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vpii vector<pii>
#define vpci vector<pair<char,int>>
#define vpic vector<pair<int,char>>
#define vi vector<int>
#define vs vector<string>
#define F first
#define S second

#define LLINF 1000000000000LL
#define INF 2000000000
#define MOD 1000000007

#define A 423742419
#define B 204235415

using namespace std;

string words[101010];
//unordered_map<ll,int> hlist;
int idlist[101010];

int main() {

    int n;
    cin >> n;

    string t;
    cin >> t;
    reverse(t.begin(), t.end());

    int w;
    cin >> w;

    set<pair<ll,int>> hlist;

    for(int i=1;i<=w;i++) {
        string word;
        cin >> word;

        words[i] = word;

        transform(word.begin(), word.end(), word.begin(), ::tolower);

        ll h=0;
        for(int j=0;j<word.length();j++) {
            h *= A;
            h += word[j];
            h %= B;
        }

        hlist.insert({h,i});
       // hlist[h] = i;
    }

    for(int i=0;i<n;i++) {
        if(i>0&&!idlist[i]) continue;
        ll h=0;
        for(int l=1;l<=1000;l++) {
            if(i+l>n) break;

            h *= A;
            h += t[i+l-1];
            h %= B;

            auto it = hlist.lower_bound({h, -1});
            if(it != hlist.end() && it->F == h) {
                idlist[i+l] = it->S;
            }
            /*cout<<1;
            if(hlist.count(h)) {
                idlist[i+l] = hlist[h];
            }

            cout<<2;*/
        }
    }

    string final="";
    int i=n;
    while(i>0) {
        final += words[idlist[i]];
        final += " ";
        i -= words[idlist[i]].length();
    }

    cout << final << endl;
    return 0;
}


#include <bits/stdc++.h>

#define _ ios_base::sync_with_stdio(0);cin.tie();
#define what_is(x) cerr << #x << " = " << x << endl;
#define what_is2(x,y) cerr << #x << " = " << x << " | " << #y << " = " << y << endl;
#define what_is_vi(v) for(auto e:v)cout<<e<<" ";cout<<endl;
#define what_is_vpii(v) for(auto e:v)cout<<"{"<<e.first<<","<<e.second<<"} ";cout<<endl;
#define padding(n) for(int i=0;i<(n);i++) cout << " ";

#define PI 3.14159265358979d

#define mp make_pair
#define pb push_back
#define eb emplace_back
//#define mt make_tuple
#define gcd __gcd

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vpii vector<pii>
#define vpci vector<pair<char,int>>
#define vpic vector<pair<int,char>>
#define vi vector<int>
#define vs vector<string>
#define F first
#define S second

#define LLINF 1000000000000LL
#define INF 2000000000
#define MOD 1000000007

#define A 423742419
#define B 204235415

using namespace std;

unordered_map<ll, int> dict;
string words[101010];
ll p[101010], x[101010];

ll h(int a, int b) {
    ll pb = p[b];
    if(a>0) pb -= (p[a-1]*x[b-a+1])%B;
    if(pb<0) pb += B;
    return pb;
}

int n;
vector<int> ids;
bool gf=false;
string final;

void f(int l, int r) {
    if(gf) return;
    if(r>=n) return;
    ll h_lr = h(l,r);
    if(dict.count(h_lr)) {
        int id = dict[h_lr];
        if(r == n-1) {
            final += words[id];
            for(int id_i=ids.size()-1;id_i>=0;id_i--) {
                final += " ";
                final += words[ids[id_i]];
            }
            gf=true;
            return;
        } else {
            ids.pb(id);
            f(r+1,r+1);
            ids.pop_back();
            f(l,r+1);
        }
    } else {
        f(l, r+1);
    }

    return;
}

int main() { _

    cin >> n;
    string t; cin >> t;
    reverse(t.begin(), t.end());

    cout << t << endl;

    p[0] = t[0];
    x[0] = 1;
    for(int i=1;i<n;i++) {
        p[i] = (p[i-1]*A+t[i])%B;
        x[i] = (x[i-1]*A)%B;
    }

    int m; cin >> m;
    for(int i=0;i<m;i++) {
        string w; cin >> w;
        words[i] = w;
        std::transform(w.begin(), w.end(), w.begin(), ::tolower);

        ll hw=0;
        for(int j=0;j<w.length();j++) {
            hw = hw*A+w[j];
            hw %= B;
        }

        dict[hw] = i;
    }

    f(0,0);
    cout << final << endl;

    return 0;
}


#include <bits/stdc++.h>

#define _ ios_base::sync_with_stdio(0);cin.tie();
#define what_is(x) cerr << #x << " = " << x << endl;
#define what_is2(x,y) cerr << #x << " = " << x << " | " << #y << " = " << y << endl;
#define what_is_vi(v) for(auto e:v)cout<<e<<" ";cout<<endl;
#define what_is_vpii(v) for(auto e:v)cout<<"{"<<e.first<<","<<e.second<<"} ";cout<<endl;
#define padding(n) for(int i=0;i<(n);i++) cout << " ";

#define PI 3.14159265358979d

#define mp make_pair
#define pb push_back
#define eb emplace_back
//#define mt make_tuple
#define gcd __gcd

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vpii vector<pii>
#define vpci vector<pair<char,int>>
#define vpic vector<pair<int,char>>
#define vi vector<int>
#define vs vector<string>
#define F first
#define S second

#define LLINF 1000000000000LL
#define INF 2000000000
#define MOD 1000000007

#define A 423742419
#define B 204235415

using namespace std;

unordered_map<ll, int> dict;
string words[101010];
ll p[101010], x[101010];

ll h(int a, int b) {
    ll pb = p[b];
    if(a>0) pb -= (p[a-1]*x[b-a+1])%B;
    if(pb<0) pb += B;
    return pb;
}

int n;
vector<int> ids;
bool gf=false;

void f(int l, int r) {
    if(gf) return;
    if(r>=n) return;
    ll h_lr = h(l,r);
    if(dict.count(h_lr)) {
        int id = dict[h_lr];
        //cout << "Matched word " << words[id] << endl;
        if(r == n-1) {
            cout << words[id];
            for(int id_i=ids.size()-1;id_i>=0;id_i--) {
                cout << " " << words[ids[id_i]];
            }
            gf=true;
            return;
        } else {
            ids.pb(id);
            f(r+1,r+1);
            ids.pop_back();
            f(l,r+1);
        }
    } else {
        f(l, r+1);
    }

    return;
}

int main() { _

    cin >> n;
    string t; cin >> t;
    reverse(t.begin(), t.end());

    cout << t << endl;

    p[0] = t[0];
    x[0] = 1;
    for(int i=1;i<n;i++) {
        p[i] = (p[i-1]*A+t[i])%B;
        x[i] = (x[i-1]*A)%B;
    }

    int m; cin >> m;
    for(int i=0;i<m;i++) {
        string w; cin >> w;
        words[i] = w;
        std::transform(w.begin(), w.end(), w.begin(), ::tolower);

        ll hw=0;
        for(int j=0;j<w.length();j++) {
            hw = hw*A+w[j];
            hw %= B;
        }

        dict[hw] = i;
    }

    f(0,0);

    return 0;
}


#include <bits/stdc++.h>

#define _ ios_base::sync_with_stdio(0);cin.tie();
#define what_is(x) cerr << #x << " = " << x << endl;
#define what_is2(x,y) cerr << #x << " = " << x << " | " << #y << " = " << y << endl;
#define what_is_vi(v) for(auto e:v)cout<<e<<" ";cout<<endl;
#define what_is_vpii(v) for(auto e:v)cout<<"{"<<e.first<<","<<e.second<<"} ";cout<<endl;
#define padding(n) for(int i=0;i<(n);i++) cout << " ";

#define PI 3.14159265358979d

#define mp make_pair
#define pb push_back
#define eb emplace_back
//#define mt make_tuple
#define gcd __gcd

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vpii vector<pii>
#define vpci vector<pair<char,int>>
#define vpic vector<pair<int,char>>
#define vi vector<int>
#define vs vector<string>
#define F first
#define S second

#define LLINF 1000000000000LL
#define INF 2000000000
#define MOD 1000000007

#define A 423742419
#define B 204235415

using namespace std;

string words[101010];
unordered_map<ll,int> hlist;
int idlist[101010];

int main() {

    int n;
    cin >> n;

    string t;
    cin >> t;
    reverse(t.begin(), t.end());

    int w;
    cin >> w;

    set<pair<ll, int>> hlist;

    for(int i=1;i<=w;i++) {
        string word;
        cin >> word;

        words[i] = word;

        transform(word.begin(), word.end(), word.begin(), ::tolower);

        ll h=0;
        for(int j=0;j<word.length();j++) {
            h *= A;
            h += word[j];
            h %= B;
        }

        hlist.insert({h,i});
    }

    for(int i=0;i<n;i++) {
        if(i!=0&&idlist[i]>0) continue;

        ll h=0;
        for(int l=1;l<=1000;l++) {
            if(i+l>n) break;

            h *= A;
            h += t[i+l-1];
            h %= B;

            auto it = hlist.lower_bound({h, -1});
            if(it != hlist.end() && it->F == h) {
                idlist[i+l-1] = it->S;
            }
        }
    }

    string final="";
    int i=n-1;
    while(i>=0) {
        final += words[idlist[i]];
        final += " ";
        i -= words[idlist[i]].length();
    }

    cout << final << endl;
    return 0;
}


#include <bits/stdc++.h>

#define _ ios_base::sync_with_stdio(0);cin.tie();
#define what_is(x) cerr << #x << " = " << x << endl;
#define what_is2(x,y) cerr << #x << " = " << x << " | " << #y << " = " << y << endl;
#define what_is_vi(v) for(auto e:v)cout<<e<<" ";cout<<endl;
#define what_is_vpii(v) for(auto e:v)cout<<"{"<<e.first<<","<<e.second<<"} ";cout<<endl;
#define padding(n) for(int i=0;i<(n);i++) cout << " ";

#define PI 3.14159265358979d

#define mp make_pair
#define pb push_back
#define eb emplace_back
//#define mt make_tuple
#define gcd __gcd

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vpii vector<pii>
#define vpci vector<pair<char,int>>
#define vpic vector<pair<int,char>>
#define vi vector<int>
#define vs vector<string>
#define F first
#define S second

#define LLINF 1000000000000LL
#define INF 2000000000
#define MOD 1000000007

#define A 423742419
#define B 204235415

using namespace std;

string words[101010];
unordered_map<ll,int> hlist;
int idlist[101010];

int main() {

    int n;
    cin >> n;

    string t;
    cin >> t;
    reverse(t.begin(), t.end());

    int w;
    cin >> w;

    for(int i=1;i<=w;i++) {
        string word;
        cin >> word;

        words[i] = word;

        transform(word.begin(), word.end(), word.begin(), ::tolower);

        ll h=0;
        for(int j=0;j<word.length();j++) {
            h *= A;
            h += word[j];
            h %= B;
        }

        hlist[h] = i;
    }

    for(int i=0;i<n;i++) {
        if(idlist[i]) continue;

        ll h=0;
        for(int l=1;l<=1000;l++) {
            if(i+l>n) break;

            h *= A;
            h += t[i+l-1];
            h %= B;

            if(hlist.count(h)) {
                idlist[i+l-1] = hlist[h];
            }
        }
    }

    string final="";
    int i=n-1;
    while(i>=0) {
        final += words[idlist[i]];
        final += " ";
        i -= words[idlist[i]].length();
    }

    cout << final << endl;
    return 0;
}


#include <bits/stdc++.h>

#define _ ios_base::sync_with_stdio(0);cin.tie();
#define what_is(x) cerr << #x << " = " << x << endl;
#define what_is2(x,y) cerr << #x << " = " << x << " | " << #y << " = " << y << endl;
#define what_is_vi(v) for(auto e:v)cout<<e<<" ";cout<<endl;
#define what_is_vpii(v) for(auto e:v)cout<<"{"<<e.first<<","<<e.second<<"} ";cout<<endl;
#define padding(n) for(int i=0;i<(n);i++) cout << " ";

#define PI 3.14159265358979d

#define mp make_pair
#define pb push_back
#define eb emplace_back
//#define mt make_tuple
#define gcd __gcd

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vpii vector<pii>
#define vpci vector<pair<char,int>>
#define vpic vector<pair<int,char>>
#define vi vector<int>
#define vs vector<string>
#define F first
#define S second

#define LLINF 1000000000000LL
#define INF 2000000000
#define MOD 1000000007

#define A 423742432
#define B 204275415

using namespace std;

string words[101010];
unordered_map<ll,int> hlist;
int idlist[101010];

int main() {

    int n;
    cin >> n;

    string t;
    cin >> t;
    reverse(t.begin(), t.end());

    int w;
    cin >> w;

   // set<pair<ll,int>> hlist;

    for(int i=1;i<=w;i++) {
        string word;
        cin >> word;

        words[i] = word;

        transform(word.begin(), word.end(), word.begin(), ::tolower);

        ll h=0;
        for(int j=0;j<word.length();j++) {
            h *= A;
            h += word[j];
            h %= B;
        }

        //hlist.insert({h,i});
        hlist[h] = i;
    }

    for(int i=0;i<n;i++) {
        if(i>0&&!idlist[i]) continue;
        ll h=0;
        for(int l=1;l<=1000;l++) {
            if(i+l>n) break;

            h *= A;
            h += t[i+l-1];
            h %= B;

            if(hlist.count(h)) {
                idlist[i+l] = hlist[h];
            }
        }
    }

    string final="";
    int i=n;
    while(i>0) {
        final += words[idlist[i]];
        final += " ";
        i -= words[idlist[i]].length();
    }

    cout << final << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const ll N = 1111111 ;
ll n , m , h[N] , now , mod = 1e9+7 , p[N] , par[N] , salam[N] ;
string s , t , qw[N] ;
map < ll , bool > is ;
map < ll , ll > bedonhichesmi ;
bool dp[N] ;
ll AliF ( ll x , ll y ){
	return ( h[y] - ( h[x-1] * p[y-x+1] ) % mod + mod ) % mod ;
}
vector < string > ans ;
int main ()
{
	p[0] = 1 ;
	for ( ll i = 1 ; i < N ; i ++ ) p[i] = ( p[i-1] * 727 ) % mod ;
	cin >> n >> s >> m ;
	s[0] = tolower ( s[0] ) ;
	h[1] = s[0] - 'a' ;
	for ( ll i = 2 ; i <= s.size() ; i ++ )
		h[i] = ( ( h[i-1] * 727 ) % mod + s[i-1] - 'a' ) % mod ;
	for ( ll i = 1 ; i <= m ; i ++ ){
		cin >> qw[i] ;
		t = qw[i] ;
		t[t.size()-1] = tolower ( t[t.size()-1] ) ;
		now = t[t.size()-1] - 'a' ;
		for ( ll j = t.size() - 2 ; j >= 0 ; j -- ){
			t[j] = tolower ( t[j] ) ;
			now = ( ( now * 727 ) % mod + t[j] - 'a' ) % mod ;
		}
//		is[now] = 1 ;
//		bedonhichesmi[now] = i ;
	}
	dp[0] = 1 ;
	for ( ll i = 1 ; i <= n ; i ++ ){
		for ( ll j = i ; j >= max ( (ll) 1 , i - 1000 ) ; j -- ){
			if ( is[AliF(j,i)] ) {
				dp[i] = dp[i] or dp[j-1] ;
				if ( dp[j-1] ) {
					par[i] = j - 1 ;
					salam[i] = bedonhichesmi[AliF(j,i)] ;
					break ;
				}
			}
		}
	}
	ll k = n ;
	while ( k ){
		cout << k << endl ;
		ans.push_back(qw[salam[k]]) ;
		k = par[k] ;
	}
	for ( ll i = ans.size() - 1 ; i >= 0 ; i -- )
		cout << ans[i] << " " ;
}


#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const ll N = 11111 ;
ll n , m , h[N] , now , mod = 1e9+7 , p[N] , par[N] , salam[N] ;
string s , t , qw[N] ;
map < ll , bool > is ;
map < ll , ll > bedonhichesmi ;
bool dp[N] ;
ll AliF ( ll x , ll y ){
	return ( h[y] - ( h[x-1] * p[y-x+1] ) % mod + mod ) % mod ;
}
vector < string > ans ;
int main ()
{
	p[0] = 1 ;
	for ( ll i = 1 ; i < N ; i ++ ) p[i] = ( p[i-1] * 727 ) % mod ;
	cin >> n >> s >> m ;
	//s[0] = tolower ( s[0] ) ;
	h[1] = s[0] - 'a' ;
	for ( ll i = 2 ; i <= s.size() ; i ++ )
		h[i] = ( ( h[i-1] * 727 ) % mod + s[i-1] - 'a' ) % mod ;
	for ( ll i = 1 ; i <= m ; i ++ ){
		cin >> qw[i] ;
		t = qw[i] ;
	//	t[t.size()-1] = tolower ( t[t.size()-1] ) ;
		now = t[t.size()-1] - 'a' ;
		for ( ll j = t.size() - 2 ; j >= 0 ; j -- ){
			t[j] = tolower ( t[j] ) ;
			now = ( ( now * 727 ) % mod + t[j] - 'a' ) % mod ;
		}
		is[now] = 1 ;
		bedonhichesmi[now] = i ;
	}
	dp[0] = 1 ;
	for ( ll i = 1 ; i <= n ; i ++ ){
		for ( ll j = i ; j >= max ( (ll) 1 , i - 1000 ) ; j -- ){
			if ( is[AliF(j,i)] ) {
				dp[i] = dp[i] or dp[j-1] ;
				if ( dp[j-1] ) {
					par[i] = j - 1 ;
					salam[i] = bedonhichesmi[AliF(j,i)] ;
					break ;
				}
			}
		}
	}
	ll k = n ;
	while ( k ){
		cout << k << endl ;
		ans.push_back(qw[salam[k]]) ;
		k = par[k] ;
	}
	for ( ll i = ans.size() - 1 ; i >= 0 ; i -- )
		cout << ans[i] << " " ;
}


#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const ll N = 11111 ;
ll n , m , h[N] , now , mod = 1e9+7 , p[N] , par[N] , salam[N] ;
string s , t , qw[N] ;
set < ll > is ;
map < ll , ll > bedonhichesmi ;
bool dp[N] ;
ll AliF ( ll x , ll y ){
	return ( h[y] - ( h[x-1] * p[y-x+1] ) % mod + mod ) % mod ;
}
vector < string > ans ;
int main ()
{
	ios::sync_with_stdio(false) ; cin.tie() ; cout.tie() ;
	p[0] = 1 ;
	for ( ll i = 1 ; i < N ; i ++ ) p[i] = ( p[i-1] * 727 ) % mod ;
	cin >> n >> s >> m ;
	s[0] = tolower ( s[0] ) ;
	h[1] = s[0] - 'a' + 411;
	for ( ll i = 2 ; i <= s.size() ; i ++ )
		h[i] = ( ( h[i-1] * 727 ) % mod + s[i-1] - 'a' + 411 ) % mod ;
	for ( ll i = 1 ; i <= m ; i ++ ){
		cin >> qw[i] ;
		t = qw[i] ;
		t[t.size()-1] = tolower ( t[t.size()-1] ) ;
		now = t[t.size()-1] - 'a' + 411 ;
		if ( t.size() != 1 )
		for ( ll j = t.size() - 2 ; j >= 0 ; j -- ){
			t[j] = tolower ( t[j] ) ;
			now = ( ( ( now * 727 ) % mod ) + ( t[j] - 'a' + 411 ) ) % mod ;
		}
		is.insert(now) ;
		bedonhichesmi[now] = i ;
	}
	dp[0] = 1 ;
	for ( ll i = 1 ; i <= n ; i ++ ){
		for ( ll j = i ; j >= max ( (ll) 1 , i - 1000 ) ; j -- ){
			if ( *( is.find(AliF(j,i) ) ) != is.size() ) {
				dp[i] = dp[i] or dp[j-1] ;
				if ( dp[j-1] ) {
					par[i] = j - 1 ;
					salam[i] = bedonhichesmi[AliF(j,i)] ;
					break ;
				}
			}
		}
	}
	ll k = n ;
	while ( k ){
		ans.push_back(qw[salam[k]]) ;
		k = par[k] ;
	}
	for ( ll i = ans.size() - 1 ; i >= 0 ; i -- )
		cout << ans[i] << " " ;
}


#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const ll N = 1111111 ;
ll n , m , h[N] , now , mod = 1e9+7 , p[N] , par[N] , salam[N] ;
string s , t , qw[N] ;
map < ll , bool > is ;
map < ll , ll > bedonhichesmi ;
bool dp[N] ;
ll AliF ( ll x , ll y ){
	return ( h[y] - ( h[x-1] * p[y-x+1] ) % mod + mod ) % mod ;
}
vector < string > ans ;
int main ()
{
	p[0] = 1 ;
	for ( ll i = 1 ; i < N ; i ++ ) p[i] = ( p[i-1] * 727 ) % mod ;
	cin >> n >> s >> m ;
	s[0] = tolower ( s[0] ) ;
	h[1] = s[0] - 'a' ;
	for ( ll i = 2 ; i <= s.size() ; i ++ )
		h[i] = ( ( h[i-1] * 727 ) % mod + s[i-1] - 'a' ) % mod ;
	for ( ll i = 1 ; i <= m ; i ++ ){
		cin >> qw[i] ;
		t = qw[i] ;
		t[t.size()-1] = tolower ( t[t.size()-1] ) ;
		now = t[t.size()-1] - 'a' ;
		for ( ll j = t.size() - 2 ; j >= 0 ; j -- ){
			t[j] = tolower ( t[j] ) ;
			now = ( ( ( now * 727 ) % mod ) + ( t[j] - 'a' ) ) % mod ;
		}
		is[now] = 1 ;
		bedonhichesmi[now] = i ;
	}
	dp[0] = 1 ;
	for ( ll i = 1 ; i <= n ; i ++ ){
		for ( ll j = i ; j >= max ( (ll) 1 , i - 1000 ) ; j -- ){
			if ( is[AliF(j,i)] ) {
				dp[i] = dp[i] or dp[j-1] ;
				if ( dp[j-1] ) {
					par[i] = j - 1 ;
					salam[i] = bedonhichesmi[AliF(j,i)] ;
					break ;
				}
			}
		}
	}
	ll k = n ;
	while ( k ){
		cout << k << endl ;
		ans.push_back(qw[salam[k]]) ;
		k = par[k] ;
	}
	for ( ll i = ans.size() - 1 ; i >= 0 ; i -- )
		cout << ans[i] << " " ;
}


#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const ll N = 1111111 ;
ll n , m , h[N] , now , mod = 1e9+7 , p[N] , par[N] , salam[N] ;
string s , t , qw[N] ;
map < ll , bool > is ;
map < ll , ll > bedonhichesmi ;
bool dp[N] ;
ll AliF ( ll x , ll y ){
	return ( h[y] - ( h[x-1] * p[y-x+1] ) % mod + mod ) % mod ;
}
vector < string > ans ;
int main ()
{
	p[0] = 1 ;
	for ( ll i = 1 ; i < N ; i ++ ) p[i] = ( p[i-1] * 727 ) % mod ;
	cin >> n >> s >> m ;
	s[0] = tolower ( s[0] ) ;
	h[1] = s[0] - 'a' ;
	for ( ll i = 2 ; i <= s.size() ; i ++ )
		h[i] = ( ( h[i-1] * 727 ) % mod + s[i-1] - 'a' ) % mod ;
	for ( ll i = 1 ; i <= m ; i ++ ){
		cin >> qw[i] ;
		t = qw[i] ;
		t[t.size()-1] = tolower ( t[t.size()-1] ) ;
		now = t[t.size()-1] - 'a' ;
		for ( ll j = t.size() - 2 ; j >= 0 ; j -- ){
			t[j] = tolower ( t[j] ) ;
			cout << j << endl ;
			now = ( ( ( now * 727 ) % mod ) + ( t[j] - 'a' ) ) % mod ;
		}
		is[now] = 1 ;
		bedonhichesmi[now] = i ;
	}
	dp[0] = 1 ;
	for ( ll i = 1 ; i <= n ; i ++ ){
		for ( ll j = i ; j >= max ( (ll) 1 , i - 1000 ) ; j -- ){
			if ( is[AliF(j,i)] ) {
				dp[i] = dp[i] or dp[j-1] ;
				if ( dp[j-1] ) {
					par[i] = j - 1 ;
					salam[i] = bedonhichesmi[AliF(j,i)] ;
					break ;
				}
			}
		}
	}
	ll k = n ;
	while ( k ){
		cout << k << endl ;
		ans.push_back(qw[salam[k]]) ;
		k = par[k] ;
	}
	for ( ll i = ans.size() - 1 ; i >= 0 ; i -- )
		cout << ans[i] << " " ;
}


#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const ll N = 1111111 ;
ll n , m , h[N] , now , mod = 1e9+7 , p[N] , par[N] , salam[N] ;
string s , t , qw[N] ;
map < ll , bool > is ;
map < ll , ll > bedonhichesmi ;
bool dp[N] ;
ll AliF ( ll x , ll y ){
	return ( h[y] - ( h[x-1] * p[y-x+1] ) % mod + mod ) % mod ;
}
vector < string > ans ;
int main ()
{
	p[0] = 1 ;
	for ( ll i = 1 ; i < N ; i ++ ) p[i] = ( p[i-1] * 727 ) % mod ;
	cin >> n >> s >> m ;
	s[0] = tolower ( s[0] ) ;
	h[1] = s[0] - 'a' ;
	for ( ll i = 2 ; i <= s.size() ; i ++ )
		h[i] = ( ( h[i-1] * 727 ) % mod + s[i-1] - 'a' ) % mod ;
	for ( ll i = 1 ; i <= m ; i ++ ){
		cin >> qw[i] ;
		t = qw[i] ;
		t[t.size()-1] = tolower ( t[t.size()-1] ) ;
		now = t[t.size()-1] - 'a' ;
		if ( t.size() != 1 )
		for ( ll j = t.size() - 2 ; j >= 0 ; j -- ){
			t[j] = tolower ( t[j] ) ;
			now = ( ( ( now * 727 ) % mod ) + ( t[j] - 'a' ) ) % mod ;
		}
		is[now] = 1 ;
		bedonhichesmi[now] = i ;
	}
	dp[0] = 1 ;
	for ( ll i = 1 ; i <= n ; i ++ ){
		for ( ll j = i ; j >= max ( (ll) 1 , i - 1000 ) ; j -- ){
			if ( is[AliF(j,i)] ) {
				dp[i] = dp[i] or dp[j-1] ;
				if ( dp[j-1] ) {
					par[i] = j - 1 ;
					salam[i] = bedonhichesmi[AliF(j,i)] ;
					break ;
				}
			}
		}
	}
	ll k = n ;
	while ( k ){
		cout << k << endl ;
		ans.push_back(qw[salam[k]]) ;
		k = par[k] ;
	}
	for ( ll i = ans.size() - 1 ; i >= 0 ; i -- )
		cout << ans[i] << " " ;
}


#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const ll N = 11111 ;
ll n , m , h[N] , now , mod = 1e9+7 , p[N] , par[N] , salam[N] ;
string s , t , qw[N] ;
map < ll , bool > is ;
map < ll , ll > bedonhichesmi ;
bool dp[N] ;
ll AliF ( ll x , ll y ){
	return ( h[y] - ( h[x-1] * p[y-x+1] ) % mod + mod ) % mod ;
}
vector < string > ans ;
int main ()
{
	p[0] = 1 ;
	for ( ll i = 1 ; i < N ; i ++ ) p[i] = ( p[i-1] * 727 ) % mod ;
	cin >> n >> s >> m ;
	s[0] = tolower ( s[0] ) ;
	h[1] = s[0] - 'a' ;
	for ( ll i = 2 ; i <= s.size() ; i ++ )
		h[i] = ( ( h[i-1] * 727 ) % mod + s[i-1] - 'a' ) % mod ;
	for ( ll i = 1 ; i <= m ; i ++ ){
		cin >> qw[i] ;
		t = qw[i] ;
		t[t.size()-1] = tolower ( t[t.size()-1] ) ;
		now = t[t.size()-1] - 'a' ;
		for ( ll j = t.size() - 2 ; j >= 0 ; j -- ){
			t[j] = tolower ( t[j] ) ;
			now = ( ( now * 727 ) % mod + t[j] - 'a' ) % mod ;
		}
		is[now] = 1 ;
		bedonhichesmi[now] = i ;
	}
	dp[0] = 1 ;
	for ( ll i = 1 ; i <= n ; i ++ ){
		for ( ll j = i ; j >= max ( (ll) 1 , i - 1000 ) ; j -- ){
			if ( is[AliF(j,i)] ) {
				dp[i] = dp[i] or dp[j-1] ;
				if ( dp[j-1] ) {
					par[i] = j - 1 ;
					salam[i] = bedonhichesmi[AliF(j,i)] ;
				}
			}
		}
	}
	ll k = s.size() ;
	while ( k ){
		ans.push_back(qw[salam[k]]) ;
		k = par[k] ;
	}
	for ( ll i = ans.size() - 1 ; i >= 0 ; i -- )
		cout << ans[i] << " " ;
}


#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const ll N = 11111 ;
ll n , m , h[N] , now , mod = 1e9+7 , p[N] , par[N] , salam[N] ;
string s , t , qw[N] ;
map < ll , bool > is ;
map < ll , ll > bedonhichesmi ;
bool dp[N] ;
ll AliF ( ll x , ll y ){
	return ( h[y] - ( h[x-1] * p[y-x+1] ) % mod + mod ) % mod ;
}
vector < string > ans ;
int main ()
{
	p[0] = 1 ;
	for ( ll i = 1 ; i < N ; i ++ ) p[i] = ( p[i-1] * 727 ) % mod ;
	cin >> n >> s >> m ;
	//s[0] = tolower ( s[0] ) ;
	h[1] = s[0] - 'a' ;
//	for ( ll i = 2 ; i <= s.size() ; i ++ )
//		h[i] = ( ( h[i-1] * 727 ) % mod + s[i-1] - 'a' ) % mod ;
	for ( ll i = 1 ; i <= m ; i ++ ){
		cin >> qw[i] ;
		t = qw[i] ;
	//	t[t.size()-1] = tolower ( t[t.size()-1] ) ;
		now = t[t.size()-1] - 'a' ;
		for ( ll j = t.size() - 2 ; j >= 0 ; j -- ){
			t[j] = tolower ( t[j] ) ;
			now = ( ( now * 727 ) % mod + t[j] - 'a' ) % mod ;
		}
		is[now] = 1 ;
		bedonhichesmi[now] = i ;
	}
	dp[0] = 1 ;
	for ( ll i = 1 ; i <= n ; i ++ ){
		for ( ll j = i ; j >= max ( (ll) 1 , i - 1000 ) ; j -- ){
			if ( is[AliF(j,i)] ) {
				dp[i] = dp[i] or dp[j-1] ;
				if ( dp[j-1] ) {
					par[i] = j - 1 ;
					salam[i] = bedonhichesmi[AliF(j,i)] ;
					break ;
				}
			}
		}
	}
	ll k = n ;
	while ( k ){
		cout << k << endl ;
		ans.push_back(qw[salam[k]]) ;
		k = par[k] ;
	}
	for ( ll i = ans.size() - 1 ; i >= 0 ; i -- )
		cout << ans[i] << " " ;
}


#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const ll N = 11111 ;
ll n , m , h[N] , now , mod = 1e9+7 , p[N] , par[N] , salam[N] ;
string s , t , qw[N] ;
map < ll , bool > is ;
map < ll , ll > bedonhichesmi ;
bool dp[N] ;
ll hash ( ll x , ll y ){
	return ( h[y] - ( h[x-1] * p[y-x+1] ) % mod + mod ) % mod ;
}
vector < string > ans ;
int main ()
{
	p[0] = 1 ;
	for ( ll i = 1 ; i < N ; i ++ ) p[i] = ( p[i-1] * 727 ) % mod ;
	cin >> n >> s >> m ;
	s[0] = tolower ( s[0] ) ;
	h[1] = s[0] - 'a' ;
	for ( ll i = 2 ; i <= s.size() ; i ++ )
		h[i] = ( ( h[i-1] * 727 ) % mod + s[i-1] - 'a' ) % mod ;
	for ( ll i = 1 ; i <= m ; i ++ ){
		cin >> qw[i] ;
		t = qw[i] ;
		t[t.size()-1] = tolower ( t[t.size()-1] ) ;
		now = t[t.size()-1] - 'a' ;
		for ( ll j = t.size() - 2 ; j >= 0 ; j -- ){
			t[j] = tolower ( t[j] ) ;
			now = ( ( now * 727 ) % mod + t[j] - 'a' ) % mod ;
		}
		is[now] = 1 ;
		bedonhichesmi[now] = i ;
	}
	dp[0] = 1 ;
	for ( ll i = 1 ; i <= n ; i ++ ){
		for ( ll j = i ; j >= max ( (ll) 1 , i - 1000 ) ; j -- ){
			if ( is[hash(j,i)] ) {
				dp[i] = dp[i] or dp[j-1] ;
				if ( dp[j-1] ) {
					par[i] = j - 1 ;
					salam[i] = bedonhichesmi[hash(j,i)] ;
				}
			}
		}
	}
	ll k = s.size() ;
	while ( k ){
		ans.push_back(qw[salam[k]]) ;
		k = par[k] ;
	}
	for ( ll i = ans.size() - 1 ; i >= 0 ; i -- )
		cout << ans[i] << " " ;
}


#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const ll N = 1111111 ;
ll n , m , h[N] , now , mod = 1e9+7 , p[N] , par[N] , salam[N] ;
string s , t , qw[N] ;
map < ll , bool > is ;
map < ll , ll > bedonhichesmi ;
bool dp[N] ;
ll AliF ( ll x , ll y ){
	return ( h[y] - ( h[x-1] * p[y-x+1] ) % mod + mod ) % mod ;
}
vector < string > ans ;
int main ()
{
	p[0] = 1 ;
	for ( ll i = 1 ; i < N ; i ++ ) p[i] = ( p[i-1] * 727 ) % mod ;
	cin >> n >> s >> m ;
	s[0] = tolower ( s[0] ) ;
	h[1] = s[0] - 'a' ;
	for ( ll i = 2 ; i <= s.size() ; i ++ )
		h[i] = ( ( h[i-1] * 727 ) % mod + s[i-1] - 'a' ) % mod ;
	for ( ll i = 1 ; i <= m ; i ++ ){
		cin >> qw[i] ;
		t = qw[i] ;
		t[t.size()-1] = tolower ( t[t.size()-1] ) ;
		now = t[t.size()-1] - 'a' ;
		if ( t.size() != 1 )
		for ( ll j = t.size() - 2 ; j >= 0 ; j -- ){
			t[j] = tolower ( t[j] ) ;
			now = ( ( ( now * 727 ) % mod ) + ( t[j] - 'a' ) ) % mod ;
		}
		is[now] = 1 ;
		bedonhichesmi[now] = i ;
	}
	dp[0] = 1 ;
	for ( ll i = 1 ; i <= n ; i ++ ){
		for ( ll j = i ; j >= max ( (ll) 1 , i - 1000 ) ; j -- ){
			if ( is[AliF(j,i)] ) {
				dp[i] = dp[i] or dp[j-1] ;
				if ( dp[j-1] ) {
					par[i] = j - 1 ;
					salam[i] = bedonhichesmi[AliF(j,i)] ;
					break ;
				}
			}
		}
	}
	ll k = n ;
	while ( k ){
		ans.push_back(qw[salam[k]]) ;
		k = par[k] ;
	}
	for ( ll i = ans.size() - 1 ; i >= 0 ; i -- )
		cout << ans[i] << " " ;
}


#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const ll N = 1111111 ;
ll n , m , h[N] , now , mod = 1e9+7 , p[N] , par[N] , salam[N] ;
string s , t , qw[N] ;
map < ll , bool > is ;
map < ll , ll > bedonhichesmi ;
bool dp[N] ;
ll AliF ( ll x , ll y ){
	return ( h[y] - ( h[x-1] * p[y-x+1] ) % mod + mod ) % mod ;
}
vector < string > ans ;
int main ()
{
	p[0] = 1 ;
	for ( ll i = 1 ; i < N ; i ++ ) p[i] = ( p[i-1] * 727 ) % mod ;
	cin >> n >> s >> m ;
	s[0] = tolower ( s[0] ) ;
	h[1] = s[0] - 'a' ;
//	for ( ll i = 2 ; i <= s.size() ; i ++ )
//		h[i] = ( ( h[i-1] * 727 ) % mod + s[i-1] - 'a' ) % mod ;
	for ( ll i = 1 ; i <= m ; i ++ ){
		cin >> qw[i] ;
		t = qw[i] ;
		t[t.size()-1] = tolower ( t[t.size()-1] ) ;
		now = t[t.size()-1] - 'a' ;
/*		for ( ll j = t.size() - 2 ; j >= 0 ; j -- ){
			t[j] = tolower ( t[j] ) ;
			now = ( ( now * 727 ) % mod + t[j] - 'a' ) % mod ;
		}
*/		is[now] = 1 ;
		bedonhichesmi[now] = i ;
	}
	dp[0] = 1 ;
	for ( ll i = 1 ; i <= n ; i ++ ){
		for ( ll j = i ; j >= max ( (ll) 1 , i - 1000 ) ; j -- ){
			if ( is[AliF(j,i)] ) {
				dp[i] = dp[i] or dp[j-1] ;
				if ( dp[j-1] ) {
					par[i] = j - 1 ;
					salam[i] = bedonhichesmi[AliF(j,i)] ;
					break ;
				}
			}
		}
	}
	ll k = n ;
	while ( k ){
		cout << k << endl ;
		ans.push_back(qw[salam[k]]) ;
		k = par[k] ;
	}
	for ( ll i = ans.size() - 1 ; i >= 0 ; i -- )
		cout << ans[i] << " " ;
}


#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const ll N = 1111111 ;
ll n , m , h[N] , now , mod = 1e9+7 , p[N] , par[N] , salam[N] ;
string s , t , qw[N] ;
map < ll , bool > is ;
map < ll , ll > bedonhichesmi ;
bool dp[N] ;
ll AliF ( ll x , ll y ){
	return ( h[y] - ( h[x-1] * p[y-x+1] ) % mod + mod ) % mod ;
}
vector < string > ans ;
int main ()
{
	p[0] = 1 ;
	for ( ll i = 1 ; i < N ; i ++ ) p[i] = ( p[i-1] * 727 ) % mod ;
	cin >> n >> s >> m ;
	s[0] = tolower ( s[0] ) ;
	h[1] = s[0] - 'a' ;
//	for ( ll i = 2 ; i <= s.size() ; i ++ )
//		h[i] = ( ( h[i-1] * 727 ) % mod + s[i-1] - 'a' ) % mod ;
	for ( ll i = 1 ; i <= m ; i ++ ){
		cin >> qw[i] ;
		t = qw[i] ;
		t[t.size()-1] = tolower ( t[t.size()-1] ) ;
		now = t[t.size()-1] - 'a' ;
		for ( ll j = t.size() - 2 ; j >= 0 ; j -- ){
			t[j] = tolower ( t[j] ) ;
			now = ( ( now * 727 ) % mod + t[j] - 'a' ) % mod ;
		}
		is[now] = 1 ;
		bedonhichesmi[now] = i ;
	}
	dp[0] = 1 ;
	for ( ll i = 1 ; i <= n ; i ++ ){
		for ( ll j = i ; j >= max ( (ll) 1 , i - 1000 ) ; j -- ){
			if ( is[AliF(j,i)] ) {
				dp[i] = dp[i] or dp[j-1] ;
				if ( dp[j-1] ) {
					par[i] = j - 1 ;
					salam[i] = bedonhichesmi[AliF(j,i)] ;
					break ;
				}
			}
		}
	}
	ll k = n ;
	while ( k ){
		cout << k << endl ;
		ans.push_back(qw[salam[k]]) ;
		k = par[k] ;
	}
	for ( ll i = ans.size() - 1 ; i >= 0 ; i -- )
		cout << ans[i] << " " ;
}


#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const ll N = 1111111 ;
ll n , m , h[N] , now , mod = 1e9+7 , p[N] , par[N] , salam[N] ;
string s , t , qw[N] ;
map < ll , bool > is ;
map < ll , ll > bedonhichesmi ;
bool dp[N] ;
ll AliF ( ll x , ll y ){
	return ( h[y] - ( h[x-1] * p[y-x+1] ) % mod + mod ) % mod ;
}
vector < string > ans ;
int main ()
{
	p[0] = 1 ;
	for ( ll i = 1 ; i < N ; i ++ ) p[i] = ( p[i-1] * 727 ) % mod ;
	cin >> n >> s >> m ;
	s[0] = tolower ( s[0] ) ;
	h[1] = s[0] - 'a' ;
	for ( ll i = 2 ; i <= s.size() ; i ++ )
		h[i] = ( ( h[i-1] * 727 ) % mod + s[i-1] - 'a' ) % mod ;
	for ( ll i = 1 ; i <= m ; i ++ ){
		cin >> qw[i] ;
		t = qw[i] ;
		t[t.size()-1] = tolower ( t[t.size()-1] ) ;
		now = t[t.size()-1] - 'a' ;
		for ( ll j = t.size() - 2 ; j >= 0 ; j -- ){
			t[j] = tolower ( t[j] ) ;
			now = ( ( now * 727 ) % mod + t[j] - 'a' ) % mod ;
		}
		is[now] = 1 ;
		bedonhichesmi[now] = i ;
	}
	dp[0] = 1 ;
	for ( ll i = 1 ; i <= n ; i ++ ){
		for ( ll j = i ; j >= max ( (ll) 1 , i - 1000 ) ; j -- ){
			if ( is[AliF(j,i)] ) {
				dp[i] = dp[i] or dp[j-1] ;
				if ( dp[j-1] ) {
					par[i] = j - 1 ;
					salam[i] = bedonhichesmi[AliF(j,i)] ;
					break ;
				}
			}
		}
	}
	ll k = n ;
	while ( k ){
		cout << k << endl ;
		ans.push_back(qw[salam[k]]) ;
		k = par[k] ;
	}
	for ( ll i = ans.size() - 1 ; i >= 0 ; i -- )
		cout << ans[i] << " " ;
}


#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const ll N = 11111 ;
ll n , m , h[N] , now , mod = 1e9+7 , p[N] , par[N] , salam[N] ;
string s , t , qw[N] ;
set < ll > is ;
map < ll , ll > bedonhichesmi ;
bool dp[N] ;
ll AliF ( ll x , ll y ){
	return ( h[y] - ( h[x-1] * p[y-x+1] ) % mod + mod ) % mod ;
}
vector < string > ans ;
int main ()
{
	ios::sync_with_stdio(false) ; cin.tie() ; cout.tie() ;
	p[0] = 1 ;
	for ( ll i = 1 ; i < N ; i ++ ) p[i] = ( p[i-1] * 727 ) % mod ;
	cin >> n >> s >> m ;
	s[0] = tolower ( s[0] ) ;
	h[1] = s[0] - 'a' ;
	for ( ll i = 2 ; i <= s.size() ; i ++ )
		h[i] = ( ( h[i-1] * 727 ) % mod + s[i-1] - 'a' ) % mod ;
	for ( ll i = 1 ; i <= m ; i ++ ){
		cin >> qw[i] ;
		t = qw[i] ;
		t[t.size()-1] = tolower ( t[t.size()-1] ) ;
		now = t[t.size()-1] - 'a' ;
		if ( t.size() != 1 )
		for ( ll j = t.size() - 2 ; j >= 0 ; j -- ){
			t[j] = tolower ( t[j] ) ;
			now = ( ( ( now * 727 ) % mod ) + ( t[j] - 'a' ) ) % mod ;
		}
		is.insert(now) ;
		bedonhichesmi[now] = i ;
	}
	dp[0] = 1 ;
	for ( ll i = 1 ; i <= n ; i ++ ){
		for ( ll j = i ; j >= max ( (ll) 1 , i - 1000 ) ; j -- ){
			if ( *( is.find(AliF(j,i) ) ) != is.size() ) {
				dp[i] = dp[i] or dp[j-1] ;
				if ( dp[j-1] ) {
					par[i] = j - 1 ;
					salam[i] = bedonhichesmi[AliF(j,i)] ;
					break ;
				}
			}
		}
	}
	ll k = n ;
	while ( k ){
		ans.push_back(qw[salam[k]]) ;
		k = par[k] ;
	}
	for ( ll i = ans.size() - 1 ; i >= 0 ; i -- )
		cout << ans[i] << " " ;
}


#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const ll N = 1111111 ;
ll n , m , h[N] , now , mod = 1e9+7 , p[N] , par[N] , salam[N] ;
string s , t , qw[N] ;
map < ll , bool > is ;
map < ll , ll > bedonhichesmi ;
bool dp[N] ;
ll AliF ( ll x , ll y ){
	return ( h[y] - ( h[x-1] * p[y-x+1] ) % mod + mod ) % mod ;
}
vector < string > ans ;
int main ()
{
	p[0] = 1 ;
	for ( ll i = 1 ; i < N ; i ++ ) p[i] = ( p[i-1] * 727 ) % mod ;
	cin >> n >> s >> m ;
	s[0] = tolower ( s[0] ) ;
	h[1] = s[0] - 'a' ;
	for ( ll i = 2 ; i <= s.size() ; i ++ )
		h[i] = ( ( h[i-1] * 727 ) % mod + s[i-1] - 'a' ) % mod ;
	for ( ll i = 1 ; i <= m ; i ++ ){
		cin >> qw[i] ;
		t = qw[i] ;
		t[t.size()-1] = tolower ( t[t.size()-1] ) ;
		now = t[t.size()-1] - 'a' ;
		for ( ll j = t.size() - 2 ; j >= 0 ; j -- ){
			t[j] = tolower ( t[j] ) ;
			now = ( ( now * 727 ) % mod + t[j] - 'a' ) % mod ;
		}
		is[now] = 1 ;
		bedonhichesmi[now] = i ;
	}
	dp[0] = 1 ;
/*	for ( ll i = 1 ; i <= n ; i ++ ){
		for ( ll j = i ; j >= max ( (ll) 1 , i - 1000 ) ; j -- ){
			if ( is[AliF(j,i)] ) {
				dp[i] = dp[i] or dp[j-1] ;
				if ( dp[j-1] ) {
					par[i] = j - 1 ;
					salam[i] = bedonhichesmi[AliF(j,i)] ;
					break ;
				}
			}
		}
	}
	ll k = n ;
	while ( k ){
		cout << k << endl ;
		ans.push_back(qw[salam[k]]) ;
		k = par[k] ;
	}
	for ( ll i = ans.size() - 1 ; i >= 0 ; i -- )
		cout << ans[i] << " " ;
*/}


#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const ll N = 111111 ;
ll n , m , h[N] , now , mod = 1e9+7 , p[N] , par[N] , salam[N] ;
string s , t , qw[N] ;
set < ll > is ;
map < ll , ll > bedonhichesmi ;
bool dp[N] ;
ll AliF ( ll x , ll y ){
	return ( h[y] - ( h[x-1] * p[y-x+1] ) % mod + mod ) % mod ;
}
vector < string > ans ;
int main ()
{
	ios::sync_with_stdio(false) ; cin.tie() ; cout.tie() ;
	p[0] = 1 ;
	for ( ll i = 1 ; i < N ; i ++ ) p[i] = ( p[i-1] * 727 ) % mod ;
	cin >> n >> s >> m ;
	s[0] = tolower ( s[0] ) ;
	h[1] = s[0] - 'a' + 411;
	for ( ll i = 2 ; i <= s.size() ; i ++ )
		h[i] = ( ( h[i-1] * 727 ) % mod + s[i-1] - 'a' + 411 ) % mod ;
	for ( ll i = 1 ; i <= m ; i ++ ){
		cin >> qw[i] ;
		t = qw[i] ;
		t[t.size()-1] = tolower ( t[t.size()-1] ) ;
		now = t[t.size()-1] - 'a' + 411 ;
		if ( t.size() != 1 )
		for ( ll j = t.size() - 2 ; j >= 0 ; j -- ){
			t[j] = tolower ( t[j] ) ;
			now = ( ( ( now * 727 ) % mod ) + ( t[j] - 'a' + 411 ) ) % mod ;
		}
		is.insert(now) ;
		bedonhichesmi[now] = i ;
	}
	dp[0] = 1 ;
	for ( ll i = 1 ; i <= n ; i ++ ){
		for ( ll j = i ; j >= max ( (ll) 1 , i - 1000 ) ; j -- ){
			if ( *( is.find(AliF(j,i) ) ) != is.size() ) {
				dp[i] = dp[i] or dp[j-1] ;
				if ( dp[j-1] ) {
					par[i] = j - 1 ;
					salam[i] = bedonhichesmi[AliF(j,i)] ;
					break ;
				}
			}
		}
	}
	ll k = n ;
	while ( k ){
		ans.push_back(qw[salam[k]]) ;
		k = par[k] ;
	}
	for ( ll i = ans.size() - 1 ; i >= 0 ; i -- )
		cout << ans[i] << " " ;
}


#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const ll N = 11111 ;
ll n , m , h[N] , now , mod = 1e9+7 , p[N] , par[N] , salam[N] ;
string s , t , qw[N] ;
map < ll , bool > is ;
map < ll , ll > bedonhichesmi ;
bool dp[N] ;
ll AliF ( ll x , ll y ){
	return ( h[y] - ( h[x-1] * p[y-x+1] ) % mod + mod ) % mod ;
}
vector < string > ans ;
int main ()
{
	p[0] = 1 ;
	for ( ll i = 1 ; i < N ; i ++ ) p[i] = ( p[i-1] * 727 ) % mod ;
	cin >> n >> s >> m ;
	//s[0] = tolower ( s[0] ) ;
	h[1] = s[0] - 'a' ;
	for ( ll i = 2 ; i <= s.size() ; i ++ )
		h[i] = ( ( h[i-1] * 727 ) % mod + s[i-1] - 'a' ) % mod ;
	for ( ll i = 1 ; i <= m ; i ++ ){
		cin >> qw[i] ;
		t = qw[i] ;
	//	t[t.size()-1] = tolower ( t[t.size()-1] ) ;
		now = t[t.size()-1] - 'a' ;
		for ( ll j = t.size() - 2 ; j >= 0 ; j -- ){
			t[j] = tolower ( t[j] ) ;
			now = ( ( now * 727 ) % mod + t[j] - 'a' ) % mod ;
		}
		is[now] = 1 ;
		bedonhichesmi[now] = i ;
	}
	dp[0] = 1 ;
	for ( ll i = 1 ; i <= n ; i ++ ){
		for ( ll j = i ; j >= max ( (ll) 1 , i - 1000 ) ; j -- ){
			if ( is[AliF(j,i)] ) {
				dp[i] = dp[i] or dp[j-1] ;
				if ( dp[j-1] ) {
					par[i] = j - 1 ;
					salam[i] = bedonhichesmi[AliF(j,i)] ;
					break ;
				}
			}
		}
	}
	ll k = s.size() ;
	while ( k ){
		ans.push_back(qw[salam[k]]) ;
		k = par[k] ;
	}
	for ( ll i = ans.size() - 1 ; i >= 0 ; i -- )
		cout << ans[i] << " " ;
}


#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const ll N = 11111 ;
ll n , m , h[N] , now , mod = 1e9+7 , p[N] , par[N] , salam[N] ;
string s , t , qw[N] ;
map < ll , bool > is ;
map < ll , ll > bedonhichesmi ;
bool dp[N] ;
ll AliF ( ll x , ll y ){
	return ( h[y] - ( h[x-1] * p[y-x+1] ) % mod + mod ) % mod ;
}
vector < string > ans ;
int main ()
{
	p[0] = 1 ;
	for ( ll i = 1 ; i < N ; i ++ ) p[i] = ( p[i-1] * 727 ) % mod ;
	cin >> n >> s >> m ;
	s[0] = tolower ( s[0] ) ;
	h[1] = s[0] - 'a' ;
	for ( ll i = 2 ; i <= s.size() ; i ++ )
		h[i] = ( ( h[i-1] * 727 ) % mod + s[i-1] - 'a' ) % mod ;
	for ( ll i = 1 ; i <= m ; i ++ ){
		cin >> qw[i] ;
		t = qw[i] ;
		t[t.size()-1] = tolower ( t[t.size()-1] ) ;
		now = t[t.size()-1] - 'a' ;
		if ( t.size() != 1 )
		for ( ll j = t.size() - 2 ; j >= 0 ; j -- ){
			t[j] = tolower ( t[j] ) ;
			now = ( ( ( now * 727 ) % mod ) + ( t[j] - 'a' ) ) % mod ;
		}
		is[now] = 1 ;
		bedonhichesmi[now] = i ;
	}
	dp[0] = 1 ;
	for ( ll i = 1 ; i <= n ; i ++ ){
		for ( ll j = i ; j >= max ( (ll) 1 , i - 1000 ) ; j -- ){
			if ( is[AliF(j,i)] ) {
				dp[i] = dp[i] or dp[j-1] ;
				if ( dp[j-1] ) {
					par[i] = j - 1 ;
					salam[i] = bedonhichesmi[AliF(j,i)] ;
					break ;
				}
			}
		}
	}
	ll k = n ;
	while ( k ){
		ans.push_back(qw[salam[k]]) ;
		k = par[k] ;
	}
	for ( ll i = ans.size() - 1 ; i >= 0 ; i -- )
		cout << ans[i] << " " ;
}


#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const ll N = 1111111 ;
ll n , m , h[N] , now , mod = 1e9+7 , p[N] , par[N] , salam[N] ;
string s , t , qw[N] ;
map < ll , bool > is ;
map < ll , ll > bedonhichesmi ;
bool dp[N] ;
ll AliF ( ll x , ll y ){
	return ( h[y] - ( h[x-1] * p[y-x+1] ) % mod + mod ) % mod ;
}
vector < string > ans ;
int main ()
{
	p[0] = 1 ;
	for ( ll i = 1 ; i < N ; i ++ ) p[i] = ( p[i-1] * 727 ) % mod ;
	cin >> n >> s >> m ;
	//s[0] = tolower ( s[0] ) ;
	h[1] = s[0] - 'a' ;
	for ( ll i = 2 ; i <= s.size() ; i ++ )
		h[i] = ( ( h[i-1] * 727 ) % mod + s[i-1] - 'a' ) % mod ;
	for ( ll i = 1 ; i <= m ; i ++ ){
		cin >> qw[i] ;
		t = qw[i] ;
	//	t[t.size()-1] = tolower ( t[t.size()-1] ) ;
		now = t[t.size()-1] - 'a' ;
		for ( ll j = t.size() - 2 ; j >= 0 ; j -- ){
			t[j] = tolower ( t[j] ) ;
			now = ( ( now * 727 ) % mod + t[j] - 'a' ) % mod ;
		}
		is[now] = 1 ;
		bedonhichesmi[now] = i ;
	}
	dp[0] = 1 ;
	for ( ll i = 1 ; i <= n ; i ++ ){
		for ( ll j = i ; j >= max ( (ll) 1 , i - 1000 ) ; j -- ){
			if ( is[AliF(j,i)] ) {
				dp[i] = dp[i] or dp[j-1] ;
				if ( dp[j-1] ) {
					par[i] = j - 1 ;
					salam[i] = bedonhichesmi[AliF(j,i)] ;
					break ;
				}
			}
		}
	}
	ll k = n ;
	while ( k ){
		cout << k << endl ;
		ans.push_back(qw[salam[k]]) ;
		k = par[k] ;
	}
	for ( ll i = ans.size() - 1 ; i >= 0 ; i -- )
		cout << ans[i] << " " ;
}


#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const ll N = 11111 ;
ll n , m , h[N] , now , mod = 1e9+7 , p[N] , par[N] , salam[N] ;
string s , t , qw[N] ;
map < ll , bool > is ;
map < ll , ll > bedonhichesmi ;
bool dp[N] ;
ll AliF ( ll x , ll y ){
	return ( h[y] - ( h[x-1] * p[y-x+1] ) % mod + mod ) % mod ;
}
vector < string > ans ;
int main ()
{
	ios::sync_with_stdio(false) ; cin.tie() ; cout.tie() ;
	p[0] = 1 ;
	for ( ll i = 1 ; i < N ; i ++ ) p[i] = ( p[i-1] * 727 ) % mod ;
	cin >> n >> s >> m ;
	s[0] = tolower ( s[0] ) ;
	h[1] = s[0] - 'a' ;
	for ( ll i = 2 ; i <= s.size() ; i ++ )
		h[i] = ( ( h[i-1] * 727 ) % mod + s[i-1] - 'a' ) % mod ;
	for ( ll i = 1 ; i <= m ; i ++ ){
		cin >> qw[i] ;
		t = qw[i] ;
		t[t.size()-1] = tolower ( t[t.size()-1] ) ;
		now = t[t.size()-1] - 'a' ;
		if ( t.size() != 1 )
		for ( ll j = t.size() - 2 ; j >= 0 ; j -- ){
			t[j] = tolower ( t[j] ) ;
			now = ( ( ( now * 727 ) % mod ) + ( t[j] - 'a' ) ) % mod ;
		}
		is[now] = 1 ;
		bedonhichesmi[now] = i ;
	}
	dp[0] = 1 ;
	for ( ll i = 1 ; i <= n ; i ++ ){
		for ( ll j = i ; j >= max ( (ll) 1 , i - 1000 ) ; j -- ){
			if ( is[AliF(j,i)] ) {
				dp[i] = dp[i] or dp[j-1] ;
				if ( dp[j-1] ) {
					par[i] = j - 1 ;
					salam[i] = bedonhichesmi[AliF(j,i)] ;
					break ;
				}
			}
		}
	}
	ll k = n ;
	while ( k ){
		ans.push_back(qw[salam[k]]) ;
		k = par[k] ;
	}
	for ( ll i = ans.size() - 1 ; i >= 0 ; i -- )
		cout << ans[i] << " " ;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <locale>
using namespace std;
#define MAXN 10005
map <string, string> mp[1006];
string in;
vector<int> ans;
vector<int> A[MAXN]; int N;
vector<int> get(int start) {
    vector<int> ans;
    if(A[start][0] >= 0) return A[start];
    //cout << start << endl;
    ans.push_back(start);
    if(start > N) return ans;
    string res = "";
    int i; for(i = start; i < N; i++) {
        res = res + in[i];
        int l = res.length();
        if(mp[l].count(res) > 0) {
            vector<int> temp = get(i + 1);
            int total = temp.size();
            if(temp[total - 1] != N) continue;
            for(int i = 0; i < total; i++) ans.push_back(temp[i]);
        }
    }
    A[start][0] = 1;A[start] = ans;
    return ans;
}
int main() {
    cin >> N;
    cin >> in;
    for(int i = 0; i <= N; i++) A[i].push_back(-1);
    int M; cin >> M;
    for(int i = 0; i < M; i++) {
        string me; cin >> me;
        string res = me;
        transform(me.begin(), me.end(), me.begin(), ::tolower);
        reverse(me.begin(), me.end());
        int l = res.length();
        mp[l][me] = res;
    }
    vector<int> ans = get(0);
    int total = ans.size();
    for(int i = 0; i < total - 1; i++) {
        int start = ans[i];
        int upto = ans[i + 1];
        string now = "";
        for(int j = start; j < upto; j++) {
            now = now + in[j];
        }
        //cout << now << endl;
        if(i != 0) cout << " ";
        int l = now.length();
        cout << mp[l][now];
    }
    cout << endl;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <locale>
using namespace std;
#define MAXN 10005
map <string, string> mp;
string in;
vector<int> ans;
vector<int> A[MAXN]; int N;
vector<int> get(int start) {
    vector<int> ans;
    if(A[start][0] >= 0) return A[start];
    //cout << start << endl;
    ans.push_back(start);
    if(start > N) return ans;
    string res = "";
    int i; for(i = start; i < N; i++) {
        res = res + in[i];
        if(mp.count(res) > 0) {
            vector<int> temp = get(i + 1);
            int total = temp.size();
            if(temp[total - 1] != N) continue;
            for(int i = 0; i < total; i++) ans.push_back(temp[i]);
        }
    }
    A[start][0] = 1;A[start] = ans;
    return ans;
}
int main() {
    cin >> N;
    cin >> in;
    for(int i = 0; i <= N; i++) A[i].push_back(-1);
    int M; cin >> M;
    for(int i = 0; i < M; i++) {
        string me; cin >> me;
        string res = me;
        transform(me.begin(), me.end(), me.begin(), ::tolower);
        reverse(me.begin(), me.end());
        mp[me] = res;
    }
    vector<int> ans = get(0);
    int total = ans.size();
    for(int i = 0; i < total - 1; i++) {
        int start = ans[i];
        int upto = ans[i + 1];
        string now = "";
        for(int j = start; j < upto; j++) {
            now = now + in[j];
        }
        //cout << now << endl;
        if(i != 0) cout << " ";
        cout << mp[now];
    }
    cout << endl;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <locale>
using namespace std;
#define MAXN 10005
string letter[MAXN * 10];
map <string, int> mp[MAXN];
string in;
vector<int> ans;
vector<int> A[MAXN]; int N;
vector<int> get(int start) {
    vector<int> ans;
    if(A[start][0] >= 0) return A[start];
    if(start == N) { A[start][0] = 1; A[start].push_back(N); return A[start];}
    string res = "";
    int flag = 0;
    int i; for(i = start; i < N; i++) {
        res = res + in[i];
        int l = res.length();
        if(mp[l].count(res) > 0) {
            vector<int> temp = get(i + 1);
            int total = temp.size();
            if(temp[0] == 0) continue;
            //for(int i = 1; i < total; i++) ans.push_back(temp[i]);
            ans.push_back(l);
            flag = 1;
            A[start][0] = 1;A[start].push_back(l);
            break;
        }
    }
    if(!flag) {A[start][0] = 0; return A[start];}

    int total = ans.size();
    //for(int i = 0; i < total; i++) A[start].push_back(ans[i]);
    //A[start] = ans;
    return A[start];
}
int main() {
    cin >> N;
    cin >> in;
    for(int i = 0; i <= N; i++) A[i].push_back(-1);
    int M; cin >> M;
    for(int i = 0; i < M; i++) {
        string me; cin >> me;
        string res = me;
        transform(me.begin(), me.end(), me.begin(), ::tolower);
        reverse(me.begin(), me.end());
        int l = me.length();
        letter[i] = res;
        mp[l][me] = i;
    }
    get(0);
    ans = A[0];
    //for(int i = 0; i < N; i++) cout << A[i][0] << " "; cout << endl;
    int total = ans.size();
    for(int start = 0, i = 1; start < N; start += A[start][1], i++) {
        int upto = start + A[start][1];
        string now = "";
        for(int j = start; j < upto; j++) {
            now = now + in[j];
        }
        //cout << now << endl;
        if(i != 1) cout << " ";
        int l = now.length();
        cout << letter[mp[l][now]];
    }
    cout << endl;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <locale>
using namespace std;
#define MAXN 10005
map <string, int> mp[MAXN];
string letter[MAXN * 10];
string in;
vector<int> ans;
vector<int> A[MAXN]; int N;
vector<int> get(int start) {
    vector<int> ans;
    if(A[start][0] >= 0) return A[start];
    //cout << start << endl;
    ans.push_back(start);
    if(start > N) return ans;
    string res = "";
    int i; for(i = start; i < N; i++) {
        res = res + in[i];
        int l = res.length();
        if(mp[l].count(res) > 0) {
            vector<int> temp = get(i + 1);
            int total = temp.size();
            if(temp[total - 1] != N) continue;
            for(int i = 0; i < total; i++) ans.push_back(temp[i]);
        }
    }
    A[start][0] = 1;A[start] = ans;
    return ans;
}
int main() {
    cin >> N;
    cin >> in;
    for(int i = 0; i <= N; i++) A[i].push_back(-1);
    int M; cin >> M;
    for(int i = 0; i < M; i++) {
        string me; cin >> me;
        string res = me;
        transform(me.begin(), me.end(), me.begin(), ::tolower);
        reverse(me.begin(), me.end());
        int l = me.length();
        letter[i] = res;
        mp[l][me] = i;
    }
    vector<int> ans = get(0);
    int total = ans.size();
    for(int i = 0; i < total - 1; i++) {
        int start = ans[i];
        int upto = ans[i + 1];
        string now = "";
        for(int j = start; j < upto; j++) {
            now = now + in[j];
        }
        //cout << now << endl;
        if(i != 0) cout << " ";
        int l = now.length();
        cout << letter[mp[l][now]];
    }
    cout << endl;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <locale>
using namespace std;
#define MAXN 10005
map <string, string> mp[1005];
string in;
vector<int> ans;
vector<int> A[MAXN]; int N;
vector<int> get(int start) {
    vector<int> ans;
    if(A[start][0] >= 0) return A[start];
    //cout << start << endl;
    ans.push_back(start);
    if(start == N) { A[start][0] = 1; A[start].push_back(N); return A[start];}
    string res = "";
    int flag = 0;
    int i; for(i = start; i < N; i++) {
        res = res + in[i];
        if(mp[res.length()].count(res) > 0) {
            vector<int> temp = get(i + 1);
            int total = temp.size();
            if(temp[0] == 0) continue;
            for(int i = 1; i < total; i++) ans.push_back(temp[i]);
            flag = 1;
            A[start][0] = 1;
            break;
        }
    }
    if(!flag) {A[start][0] = 0; return A[start];}

    int total = ans.size();
    for(int i = 0; i < total; i++) A[start].push_back(ans[i]);
    //A[start] = ans;
    return A[start];
}
int main() {
    cin >> N;
    cin >> in;
    for(int i = 0; i <= N; i++) A[i].push_back(-1);
    int M; cin >> M;
    for(int i = 0; i < M; i++) {
        string me; cin >> me;
        string res = me;
        transform(me.begin(), me.end(), me.begin(), ::tolower);
        reverse(me.begin(), me.end());
        mp[me.length()][me] = res;
    }
    get(0);
    ans = A[0];
    //for(int i = 0; i < N; i++) cout << A[i][0] << " "; cout << endl;
    int total = ans.size();
    //for(int i = 0; i < total; i++) cout << ans[i] << " "; cout << endl;
    for(int i = 1; i < total - 1; i++) {
        int start = ans[i];
        int upto = ans[i + 1];
        string now = "";
        for(int j = start; j < upto; j++) {
            now = now + in[j];
        }
        //cout << now << endl;
        if(i != 1) cout << " ";
        cout << mp[now.length()][now];
    }
    cout << endl;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <locale>
using namespace std;
#define MAXN 10005
string letter[MAXN * 10];
map <string, int> mp[MAXN];
string in;
vector<int> ans;
vector<int> A[MAXN]; int N;
vector<int> get(int start) {
    vector<int> ans;
    if(A[start][0] >= 0) return A[start];
    //cout << start << endl;
    ans.push_back(start);
    if(start == N) { A[start][0] = 1; A[start].push_back(N); return A[start];}
    string res = "";
    int flag = 0;
    int i; for(i = start; i < N; i++) {
        res = res + in[i];
        int l = res.length();
        if(mp[l].count(res) > 0) {
            vector<int> temp = get(i + 1);
            int total = temp.size();
            if(temp[0] == 0) continue;
            for(int i = 1; i < total; i++) ans.push_back(temp[i]);
            flag = 1;
            A[start][0] = 1;
            break;
        }
    }
    if(!flag) {A[start][0] = 0; return A[start];}

    int total = ans.size();
    for(int i = 0; i < total; i++) A[start].push_back(ans[i]);
    //A[start] = ans;
    return A[start];
}
int main() {
    cin >> N;
    cin >> in;
    for(int i = 0; i <= N; i++) A[i].push_back(-1);
    int M; cin >> M;
    for(int i = 0; i < M; i++) {
        string me; cin >> me;
        string res = me;
        transform(me.begin(), me.end(), me.begin(), ::tolower);
        reverse(me.begin(), me.end());
        int l = me.length();
        letter[i] = res;
        mp[l][me] = i;
    }
    get(0);
    ans = A[0];
    //for(int i = 0; i < N; i++) cout << A[i][0] << " "; cout << endl;
    int total = ans.size();
    //for(int i = 0; i < total; i++) cout << ans[i] << " "; cout << endl;
    for(int i = 1; i < total - 1; i++) {
        int start = ans[i];
        int upto = ans[i + 1];
        string now = "";
        for(int j = start; j < upto; j++) {
            now = now + in[j];
        }
        //cout << now << endl;
        if(i != 1) cout << " ";
        int l = now.length();
        cout << letter[mp[l][now]];
    }
    cout << endl;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <locale>
using namespace std;
#define MAXN 10005
map <string, int> mp;
string letter[MAXN * 10];
string in;
vector<int> ans;
vector<int> A[MAXN]; int N;
vector<int> get(int start) {
    vector<int> ans;
    if(A[start][0] >= 0) return A[start];
    //cout << start << endl;
    ans.push_back(start);
    if(start > N) return ans;
    string res = "";
    int i; for(i = start; i < N; i++) {
        res = res + in[i];
        int l = res.length();
        if(mp.count(res) > 0) {
            vector<int> temp = get(i + 1);
            int total = temp.size();
            if(temp[total - 1] != N) continue;
            for(int i = 0; i < total; i++) ans.push_back(temp[i]);
        }
    }
    A[start][0] = 1;A[start] = ans;
    return ans;
}
int main() {
    cin >> N;
    cin >> in;
    for(int i = 0; i <= N; i++) A[i].push_back(-1);
    int M; cin >> M;
    for(int i = 0; i < M; i++) {
        string me; cin >> me;
        string res = me;
        transform(me.begin(), me.end(), me.begin(), ::tolower);
        reverse(me.begin(), me.end());
        int l = me.length();
        letter[i] = res;
        mp[me] = i;
    }
    vector<int> ans = get(0);
    int total = ans.size();
    for(int i = 0; i < total - 1; i++) {
        int start = ans[i];
        int upto = ans[i + 1];
        string now = "";
        for(int j = start; j < upto; j++) {
            now = now + in[j];
        }
        //cout << now << endl;
        if(i != 0) cout << " ";
        int l = now.length();
        cout << letter[mp[now]];
    }
    cout << endl;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <locale>
using namespace std;
#define MAXN 10005
map <string, string> mp[1006];
string in;
vector<int> ans;
vector<int> A[MAXN]; int N;
vector<int> get(int start) {
    vector<int> ans;
    if(A[start][0] >= 0) return A[start];
    //cout << start << endl;
    ans.push_back(start);
    if(start > N) return ans;
    string res = "";
    int i; for(i = start; i < N; i++) {
        res = res + in[i];
        int l = res.length();
        if(mp[l].count(res) > 0) {
            vector<int> temp = get(i + 1);
            int total = temp.size();
            if(temp[total - 1] != N) continue;
            for(int i = 0; i < total; i++) ans.push_back(temp[i]);
        }
    }
    A[start][0] = 1;A[start] = ans;
    return ans;
}
int main() {
    cin >> N;
    cin >> in;
    for(int i = 0; i <= N; i++) A[i].push_back(-1);
    int M; cin >> M;
    for(int i = 0; i < M; i++) {
        string me; cin >> me;
        string res = me;
        transform(me.begin(), me.end(), me.begin(), ::tolower);
        reverse(me.begin(), me.end());
        int l = me.length();
        mp[l][me] = res;
    }
    vector<int> ans = get(0);
    int total = ans.size();
    for(int i = 0; i < total - 1; i++) {
        int start = ans[i];
        int upto = ans[i + 1];
        string now = "";
        for(int j = start; j < upto; j++) {
            now = now + in[j];
        }
        //cout << now << endl;
        if(i != 0) cout << " ";
        int l = now.length();
        cout << mp[l][now];
    }
    cout << endl;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <locale>
using namespace std;
#define MAXN 10005
map <string, string> mp;
string in;
vector<int> ans;
vector<int> A[MAXN]; int N;
vector<int> get(int start) {
    vector<int> ans;
    if(A[start][0] >= 0) return A[start];
    //cout << start << endl;
    ans.push_back(start);
    if(start > N) return ans;
    string res = "";
    int i; for(i = start; i < N; i++) {
        res = res + in[i];
        int l = res.length();
        if(mp.count(res) > 0) {
            vector<int> temp = get(i + 1);
            int total = temp.size();
            if(temp[total - 1] != N) continue;
            for(int i = 0; i < total; i++) ans.push_back(temp[i]);
        }
    }
    A[start][0] = 1;A[start] = ans;
    return ans;
}
int main() {
    cin >> N;
    cin >> in;
    for(int i = 0; i <= N; i++) A[i].push_back(-1);
    int M; cin >> M;
    for(int i = 0; i < M; i++) {
        string me; cin >> me;
        string res = me;
        transform(me.begin(), me.end(), me.begin(), ::tolower);
        reverse(me.begin(), me.end());
        int l = me.length();
        mp[me] = res;
    }
    vector<int> ans = get(0);
    int total = ans.size();
    for(int i = 0; i < total - 1; i++) {
        int start = ans[i];
        int upto = ans[i + 1];
        string now = "";
        for(int j = start; j < upto; j++) {
            now = now + in[j];
        }
        //cout << now << endl;
        if(i != 0) cout << " ";
        int l = now.length();
        cout << mp[now];
    }
    cout << endl;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <locale>
using namespace std;
#define MAXN 10005
string letter[MAXN * 10];
map <string, int> mp;
string in;
vector<int> ans;
vector<int> A[MAXN]; int N;
vector<int> get(int start) {
    vector<int> ans;
    if(A[start][0] >= 0) return A[start];
    if(start == N) { A[start][0] = 1; A[start].push_back(N); return A[start];}
    string res = "";
    int flag = 0;
    int i; for(i = start; i < N; i++) {
        res = res + in[i];
        int l = res.length();
        if(mp.count(res) > 0) {
            vector<int> temp = get(i + 1);
            int total = temp.size();
            if(temp[0] == 0) continue;
            ans.push_back(l);
            flag = 1;
            A[start][0] = 1;A[start].push_back(l);
            break;
        }
    }
    if(!flag) {A[start][0] = 0; return A[start];}
    return A[start];
}
int main() {
    cin >> N;
    cin >> in;
    for(int i = 0; i <= N; i++) A[i].push_back(-1);
    int M; cin >> M;
    for(int i = 0; i < M; i++) {
        string me; cin >> me;
        string res = me;
        transform(me.begin(), me.end(), me.begin(), ::tolower);
        reverse(me.begin(), me.end());
        int l = me.length();
        letter[i] = res;
        mp[me] = i;
    }
    get(0);
    for(int start = 0, i = 1; start < N; start += A[start][1], i++) {
        int upto = start + A[start][1];
        string now = "";
        for(int j = start; j < upto; j++) {
            now = now + in[j];
        }
        if(i != 1) cout << " ";
        int l = now.length();
        cout << letter[mp[now]];
    }
    cout << endl;
}


#include <bits/stdc++.h>
using namespace std;
struct node {
	int wordcount;
	int precount;
	struct node *child[26];
};
struct node *initialise()
{
	struct node *newnode = (struct node *)malloc(sizeof(struct node));
	newnode->wordcount = 0;
	newnode->precount = 0;
	for(int i = 0; i < 26; i++) {
		newnode->child[i] = NULL;
	}
	return newnode;
}
struct node *addword(string s,struct node *root)
{
	int i;
	int ch;
	struct node *temp = root;
	struct node *newnode = NULL;

	for(i = 0; i < s.size(); i++) {
		ch = s[i]-'a';
		if(temp->child[ch] == NULL) {
			newnode = initialise();
			newnode->precount = 1;
			temp->child[ch] = newnode;
			temp = temp->child[ch];
		}
		else {
			temp->child[ch]->precount += 1;
			temp = temp->child[ch];
		}
	}
	temp->wordcount += 1;
	temp->precount += 1;
	return root;
}
int wordcount(string s,struct node *root)
{
	int i;
	int ch;
	struct node *temp = root;

	for(i = 0; i < s.size(); i++) {
		ch = s[i]-'a';
		if(temp->child[ch] == NULL) {
			return 0;
		}
		else {
			temp = temp->child[ch];
		}
	}
	return temp->wordcount;
}
int main()
{
	struct node *root = initialise();
	string s,s1,s2,t;
	map<string,string> m1;
	vector<string> v;
	int n;
	int m;
	int q;
	int i;

	cin>>n;
	cin>>s;
	cin>>m;
	for(i = 0; i < m; i++) {
		cin>>s1;
		s2 = s1;
		transform(s1.begin(), s1.end(), s1.begin(), ::tolower);
		m1[s1] = s2;
		reverse(s1.begin(),s1.end());
		root = addword(s1,root);
	}
	for(i = 0; i < n; i++) {
        t = t + s[i];
        if(wordcount(t,root) >= 1) {
            reverse(t.begin(),t.end());
            v.push_back(t);
            t.clear();
        }
	}
	n = v.size();
	for(i = 0; i < n; i++) {
        cout<<m1[v[i]]<<' ';
	}

}


#include <bits/stdc++.h>
using namespace std;
struct node {
    int id;
	struct node *child[26];
};
struct node *initialise()
{
	struct node *newnode = (struct node *)malloc(sizeof(struct node));
	newnode->id = 0;
	for(int i = 0; i < 26; i++) {
		newnode->child[i] = NULL;
	}
	return newnode;
}
struct node *root = initialise();
struct node *addword(string s,int id,struct node *root)
{
	int i;
	int ch;
	struct node *temp = root;
	struct node *newnode = NULL;

	for(i = 0; i < s.size(); i++) {
		ch = s[i]-'a';

		if(temp->child[ch] == NULL) {
			newnode = initialise();
			temp->child[ch] = newnode;
			temp = temp->child[ch];
		}
		else {
			temp = temp->child[ch];
		}

	}
	temp->id = id+1;
	return root;
}
string s1[100005];
string s;
int len;
int dp[100005];
vector<string> ans;
int f(int pos)
{
    struct node *temp = root;
    //cout<<pos<<endl;
    if(pos == len) {
        return 1;
    }

    if(dp[pos] != -1) {
        return dp[pos];
    }

    for(int i = pos; i < len; i++) {
        int ch = s[i]-'a';
        if(temp->child[ch] && temp->child[ch]->id) {
            if(f(i+1)) {
                ans.push_back(s1[temp->child[ch]->id-1]);
                dp[pos] = 1;
                return dp[pos];
            }
            else {
                temp = temp->child[ch];
            }
        }
        else if(temp->child[ch]) {
            temp = temp->child[ch];
        }
        else {
            dp[pos] = 0;
            return dp[pos];
        }
    }
    dp[pos] = 0;

}
int main()
{

	string s2,t;
	vector<string> v;
	int n;
	int m;
	int q;
	int i;

	cin>>n;
	cin>>s;
	cin>>m;
	len = s.size();
	for(i = 0; i <= len; i++) {
        dp[i] = -1;
	}
	for(i = 0; i < m; i++) {
		cin>>s1[i];
		s2 = s1[i];
		transform(s2.begin(), s2.end(), s2.begin(), ::tolower);
		reverse(s2.begin(),s2.end());
		root = addword(s2,i,root);
	}
	f(0);
	for(i = ans.size()-1; i >= 0; i--) {
        cout<<ans[i]<<' ';
	}

}


#include <bits/stdc++.h>
using namespace std;
struct node {
    int id;
	struct node *child[26];
};
struct node *initialise()
{
	struct node *newnode = (struct node *)malloc(sizeof(struct node));
	newnode->id = 0;
	for(int i = 0; i < 26; i++) {
		newnode->child[i] = NULL;
	}
	return newnode;
}
struct node *root = initialise();
struct node *addword(string s,int id,struct node *root)
{
	int i;
	int ch;
	struct node *temp = root;
	struct node *newnode = NULL;

	for(i = 0; i < s.size(); i++) {
		ch = s[i]-'a';

		if(temp->child[ch] == NULL) {
			newnode = initialise();
			temp->child[ch] = newnode;
			temp = temp->child[ch];
		}
		else {
			temp = temp->child[ch];
		}

	}
	temp->id = id+1;
	return root;
}
string s1[100005];
string s;
int len;
int dp[100005];
vector<string> ans;
int f(int pos)
{
    struct node *temp = root;
    //cout<<pos<<endl;
    if(pos == len) {
        return 1;
    }

    if(dp[pos] != -1) {
        return dp[pos];
    }

    for(int i = pos; i < len; i++) {
        int ch = s[i]-'a';
        if(temp->child[ch] && temp->child[ch]->id) {
            if(f(i+1)) {
                ans.push_back(s1[temp->child[ch]->id-1]);
                dp[pos] = 1;
                return dp[pos];
            }
            else {
                temp = temp->child[ch];
            }
        }
        if(temp->child[ch]) {
            temp = temp->child[ch];
        }
        else {
            dp[pos] = 0;
            return dp[pos];
        }
    }

}
int main()
{

	string s2,t;
	vector<string> v;
	int n;
	int m;
	int q;
	int i;

	cin>>n;
	cin>>s;
	cin>>m;
	len = s.size();
	for(i = 0; i <= len; i++) {
        dp[i] = -1;
	}
	for(i = 0; i < m; i++) {
		cin>>s1[i];
		s2 = s1[i];
		transform(s2.begin(), s2.end(), s2.begin(), ::tolower);
		reverse(s2.begin(),s2.end());
		root = addword(s2,i,root);
	}
	f(0);
	for(i = ans.size()-1; i >= 0; i--) {
        cout<<ans[i]<<' ';
	}

}


#include <bits/stdc++.h>
using namespace std;
struct node {
	int wordcount;
    int id;
	struct node *child[26];
};
struct node *initialise()
{
	struct node *newnode = (struct node *)malloc(sizeof(struct node));
	newnode->wordcount = 0;
	for(int i = 0; i < 26; i++) {
		newnode->child[i] = NULL;
	}
	return newnode;
}
struct node *root = initialise();
struct node *addword(string s,int id,struct node *root)
{
	int i;
	int ch;
	struct node *temp = root;
	struct node *newnode = NULL;

	for(i = 0; i < s.size(); i++) {
		ch = s[i]-'a';

		if(temp->child[ch] == NULL) {
			newnode = initialise();
			temp->child[ch] = newnode;
			temp = temp->child[ch];
		}
		else {
			temp = temp->child[ch];
		}

	}
	temp->wordcount += 1;
	temp->id = id;
	return root;
}
string s1[100005];
string s;
int len;
int dp[100005];
vector<string> ans;
int f(int pos)
{
    struct node *temp = root;
    //cout<<pos<<endl;
    if(pos == len) {
        return 1;
    }

    if(dp[pos] != -1) {
        return dp[pos];
    }

    for(int i = pos; i < len; i++) {
        int ch = s[i]-'a';
        if(temp->child[ch] && temp->child[ch]->wordcount >= 1) {
            if(f(i+1)) {
                ans.push_back(s1[temp->child[ch]->id]);
                dp[pos] = 1;
                return dp[pos];
            }
            else {
                temp = temp->child[ch];
            }
        }
        if(temp->child[ch]) {
            temp = temp->child[ch];
        }
        else {
            dp[pos] = 0;
            return dp[pos];
        }
    }

}
int main()
{

	string s2,t;
	map<string,string> m1;
	vector<string> v;
	int n;
	int m;
	int q;
	int i;

	cin>>n;
	cin>>s;
	cin>>m;
	len = s.size();
	for(i = 0; i <= len; i++) {
        dp[i] = -1;
	}
	for(i = 0; i < m; i++) {
		cin>>s1[i];
		s2 = s1[i];
		transform(s2.begin(), s2.end(), s2.begin(), ::tolower);
		//m1[s1] = s2;
		reverse(s2.begin(),s2.end());
		root = addword(s2,i,root);
	}
	f(0);
	for(i = ans.size()-1; i >= 0; i--) {
        cout<<ans[i]<<' ';
	}

}


#include <bits/stdc++.h>
using namespace std;
struct node {
	int wordcount;
    int id;
	struct node *child[26];
};
struct node *initialise()
{
	struct node *newnode = (struct node *)malloc(sizeof(struct node));
	newnode->wordcount = 0;
	for(int i = 0; i < 26; i++) {
		newnode->child[i] = NULL;
	}
	return newnode;
}
struct node *root = initialise();
struct node *addword(string s,int id,struct node *root)
{
	int i;
	int ch;
	struct node *temp = root;
	struct node *newnode = NULL;

	for(i = 0; i < s.size(); i++) {
		ch = s[i]-'a';

		if(temp->child[ch] == NULL) {
			newnode = initialise();
			temp->child[ch] = newnode;
			temp = temp->child[ch];
		}
		else {
			temp = temp->child[ch];
		}

	}
	temp->wordcount += 1;
	temp->id = id;
	return root;
}
string s1[100005];
string s;
int len;
int dp[100005];
vector<string> ans;
int f(int pos)
{
    struct node *temp = root;
    //cout<<pos<<endl;
    if(pos == len) {
        return 1;
    }

    if(dp[pos] != -1) {
        return dp[pos];
    }

    for(int i = pos; i < len; i++) {
        int ch = s[i]-'a';
        if(temp->child[ch] && temp->child[ch]->wordcount >= 1) {
            if(f(i+1)) {
                ans.push_back(s1[temp->child[ch]->id]);
                dp[pos] = 1;
                return dp[pos];
            }
            else {
                temp = temp->child[ch];
            }
        }
        if(temp->child[ch]) {
            temp = temp->child[ch];
        }
        else {
            dp[pos] = 0;
            return dp[pos];
        }
    }
    dp[pos] = 0;
    return dp[pos];

}
int main()
{

	string s2,t;
	map<string,string> m1;
	vector<string> v;
	int n;
	int m;
	int q;
	int i;

	cin>>n;
	cin>>s;
	cin>>m;
	len = s.size();
	for(i = 0; i <= len; i++) {
        dp[i] = -1;
	}
	for(i = 0; i < m; i++) {
		cin>>s1[i];
		s2 = s1[i];
		transform(s2.begin(), s2.end(), s2.begin(), ::tolower);
		//m1[s1] = s2;
		reverse(s2.begin(),s2.end());
		root = addword(s2,i,root);
	}
	f(0);
	for(i = ans.size()-1; i >= 0; i--) {
        cout<<ans[i]<<' ';
	}

}


#include <bits/stdc++.h>
using namespace std;
struct node {
	int wordcount;
    int id;
	struct node *child[26];
};
struct node *initialise()
{
	struct node *newnode = (struct node *)malloc(sizeof(struct node));
	newnode->wordcount = 0;
	for(int i = 0; i < 26; i++) {
		newnode->child[i] = NULL;
	}
	return newnode;
}
struct node *root = initialise();
struct node *addword(string s,int id,struct node *root)
{
	int i;
	int ch;
	struct node *temp = root;
	struct node *newnode = NULL;

	for(i = 0; i < s.size(); i++) {
		ch = s[i]-'a';

		if(temp->child[ch] == NULL) {
			newnode = initialise();
			temp->child[ch] = newnode;
			temp = temp->child[ch];
		}
		else {
			temp = temp->child[ch];
		}

	}
	temp->wordcount += 1;
	temp->id = id;
	return root;
}
string s1[100005];
string s;
int len;
int dp[100005];
vector<string> ans;
int f(int pos)
{
    struct node *temp = root;
    if(pos == len) {
        return 1;
    }
    if(dp[pos] != -1) {
        return dp[pos];
    }
    for(int i = pos; i < len; i++) {
        int ch = s[i]-'a';
        if(temp->child[ch] && temp->child[ch]->wordcount >= 1) {
            if(f(i+1)) {
                ans.push_back(s1[temp->child[ch]->id]);
                dp[pos] = 1;
                return dp[pos];
            }
            else {
                temp = temp->child[ch];
            }
        }
        temp = temp->child[ch];
    }
    dp[pos] = 0;
    return dp[pos];
}
int main()
{

	string s2,t;
	map<string,string> m1;
	vector<string> v;
	int n;
	int m;
	int q;
	int i;

	cin>>n;
	cin>>s;
	cin>>m;
	len = s.size();
	for(i = 0; i <= len; i++) {
        dp[i] = -1;
	}
	for(i = 0; i < m; i++) {
		cin>>s1[i];
		s2 = s1[i];
		transform(s2.begin(), s2.end(), s2.begin(), ::tolower);
		//m1[s1] = s2;
		reverse(s2.begin(),s2.end());
		root = addword(s2,i,root);
	}
	f(0);
	for(i = ans.size()-1; i >= 0; i--) {
        cout<<ans[i]<<' ';
	}

}


#include <bits/stdc++.h>
using namespace std;
struct node {
	int wordcount;
    int id;
	struct node *child[26];
};
struct node *initialise()
{
	struct node *newnode = (struct node *)malloc(sizeof(struct node));
	newnode->wordcount = 0;
	for(int i = 0; i < 26; i++) {
		newnode->child[i] = NULL;
	}
	return newnode;
}
struct node *root = initialise();
struct node *addword(string s,int id,struct node *root)
{
	int i;
	int ch;
	struct node *temp = root;
	struct node *newnode = NULL;

	for(i = 0; i < s.size(); i++) {
		ch = s[i]-'a';

		if(temp->child[ch] == NULL) {
			newnode = initialise();
			temp->child[ch] = newnode;
			temp = temp->child[ch];
		}
		else {
			temp = temp->child[ch];
		}

	}
	temp->wordcount += 1;
	temp->id = id;
	return root;
}
string s1[100005];
string s;
int len;
int dp[100005];
vector<string> ans;
int f(int pos)
{
    struct node *temp = root;
    if(pos == len) {
        return 1;
    }
    if(dp[pos] != -1) {
        return dp[pos];
    }
    //cout<<pos<<endl;
    for(int i = pos; i < len; i++) {
        int ch = s[i]-'a';
        if(temp->child[ch] && temp->child[ch]->wordcount >= 1) {
            if(f(i+1)) {
                ans.push_back(s1[temp->child[ch]->id]);
                dp[pos] = 1;
                return dp[pos];
            }
            else {
                temp = temp->child[ch];
            }
        }
        if(temp->child[ch]) {
            temp = temp->child[ch];
        }
    }
    //cout<<"sss"<<endl;
    dp[pos] = 0;
    return dp[pos];
}
int main()
{

	string s2,t;
	map<string,string> m1;
	vector<string> v;
	int n;
	int m;
	int q;
	int i;

	cin>>n;
	cin>>s;
	cin>>m;
	len = s.size();
	for(i = 0; i <= len; i++) {
        dp[i] = -1;
	}
	for(i = 0; i < m; i++) {
		cin>>s1[i];
		s2 = s1[i];
		transform(s2.begin(), s2.end(), s2.begin(), ::tolower);
		//m1[s1] = s2;
		reverse(s2.begin(),s2.end());
		root = addword(s2,i,root);
	}
	f(0);
	for(i = ans.size()-1; i >= 0; i--) {
        cout<<ans[i]<<' ';
	}

}


#include <bits/stdc++.h>
using namespace std;
struct node {
	int wordcount;
    int id;
	struct node *child[26];
};
struct node *initialise()
{
	struct node *newnode = (struct node *)malloc(sizeof(struct node));
	newnode->wordcount = 0;
	for(int i = 0; i < 26; i++) {
		newnode->child[i] = NULL;
	}
	return newnode;
}
struct node *root = initialise();
struct node *addword(string s,int id,struct node *root)
{
	int i;
	int ch;
	struct node *temp = root;
	struct node *newnode = NULL;

	for(i = 0; i < s.size(); i++) {
		ch = s[i]-'a';

		if(temp->child[ch] == NULL) {
			newnode = initialise();
			temp->child[ch] = newnode;
			temp = temp->child[ch];
		}
		else {
			temp = temp->child[ch];
		}

	}
	temp->wordcount += 1;
	temp->id = id;
	return root;
}
string s1[100005];
string s;
int len;
int dp[100005];
vector<string> ans;
int f(int pos)
{
    struct node *temp = root;
    if(pos == len) {
        return 1;
    }
    if(dp[pos] != -1) {
        return dp[pos];
    }
    //cout<<pos<<endl;
    for(int i = pos; i < len; i++) {
        int ch = s[i]-'a';
        if(temp->child[ch] && temp->child[ch]->wordcount >= 1) {
            if(f(i+1)) {
                ans.push_back(s1[temp->child[ch]->id]);
                dp[pos] = 1;
                return dp[pos];
            }
            else {
                temp = temp->child[ch];
            }
        }
        if(temp->child[ch]) {
            temp = temp->child[ch];
        }
        else {
            break;
        }
    }
    //cout<<"sss"<<endl;
    dp[pos] = 0;
    return dp[pos];
}
int main()
{

	string s2,t;
	map<string,string> m1;
	vector<string> v;
	int n;
	int m;
	int q;
	int i;

	cin>>n;
	cin>>s;
	cin>>m;
	len = s.size();
	for(i = 0; i <= len; i++) {
        dp[i] = -1;
	}
	for(i = 0; i < m; i++) {
		cin>>s1[i];
		s2 = s1[i];
		transform(s2.begin(), s2.end(), s2.begin(), ::tolower);
		//m1[s1] = s2;
		reverse(s2.begin(),s2.end());
		root = addword(s2,i,root);
	}
	f(0);
	for(i = ans.size()-1; i >= 0; i--) {
        cout<<ans[i]<<' ';
	}

}


#include <bits/stdc++.h>
using namespace std;
struct node {
	int wordcount;
    int id;
	struct node *child[26];
};
struct node *initialise()
{
	struct node *newnode = (struct node *)malloc(sizeof(struct node));
	newnode->wordcount = 0;
	newnode->id = 0;
	for(int i = 0; i < 26; i++) {
		newnode->child[i] = NULL;
	}
	return newnode;
}
struct node *root = initialise();
struct node *addword(string s,int id,struct node *root)
{
	int i;
	int ch;
	struct node *temp = root;
	struct node *newnode = NULL;

	for(i = 0; i < s.size(); i++) {
		ch = s[i]-'a';

		if(temp->child[ch] == NULL) {
			newnode = initialise();
			temp->child[ch] = newnode;
			temp = temp->child[ch];
		}
		else {
			temp = temp->child[ch];
		}

	}
	temp->wordcount += 1;
	temp->id = id;
	return root;
}
string s1[100005];
string s;
int len;
int dp[100005];
vector<string> ans;
int main()
{

	string s2,t;
	map<string,string> m1;
	vector<string> v;
	int n;
	int m;
	int q;
	int i;
	int j;

	cin>>n;
	cin>>s;
	cin>>m;
	len = s.size();
	for(i = 0; i < m; i++) {
		cin>>s1[i];
		s2 = s1[i];
		transform(s2.begin(), s2.end(), s2.begin(), ::tolower);
		//m1[s1] = s2;
		reverse(s2.begin(),s2.end());
		root = addword(s2,i+1,root);
	}
	dp[n+1] = 1;
	for(i = n; i >= 1; i--) {
        struct node *temp = root;
        for(j = i; j <= n; j++) {
            int ch = s[j-1]-'a';
            if(!temp->child[ch]) {
                break;
            }

            if(temp->child[ch]->id && dp[j+1]) {
                dp[i] = temp->child[ch]->id;
            }
            temp = temp->child[ch];
        }
	}
	int x = 1;
	while(x <= n) {
        cout<<s1[dp[x]-1]<<' ';
        x += s1[dp[x]-1].size();
	}

}


#include <bits/stdc++.h>
using namespace std;
struct node {
	int wordcount;
	int precount;
	struct node *child[26];
};
struct node *initialise()
{
	struct node *newnode = (struct node *)malloc(sizeof(struct node));
	newnode->wordcount = 0;
	newnode->precount = 0;
	for(int i = 0; i < 26; i++) {
		newnode->child[i] = NULL;
	}
	return newnode;
}
struct node *addword(string s,struct node *root)
{
	int i;
	int ch;
	struct node *temp = root;
	struct node *newnode = NULL;

	for(i = 0; i < s.size(); i++) {
		ch = s[i]-'a';

		if(temp->child[ch] == NULL) {
			newnode = initialise();
			newnode->precount = 1;
			temp->child[ch] = newnode;
			temp = temp->child[ch];
		}
		else {
			temp->child[ch]->precount += 1;
			temp = temp->child[ch];
		}

	}
	temp->wordcount += 1;
	return root;
}
int prefixcount(string s,struct node *root)
{
	int i;
	int ch;
	struct node *temp = root;

	for(i = 0; i < s.size(); i++) {
		ch = s[i] - 'a';
		if(temp->child[ch] == NULL) {
			return 0;
		}
		else {
			temp = temp->child[ch];
		}
	}
	return temp->precount;
}
int wordcount(string s,struct node *root)
{
	int i;
	int ch;
	struct node *temp = root;

	for(i = 0; i < s.size(); i++) {
		ch = s[i]-'a';
		if(temp->child[ch] == NULL) {
			return 0;
		}
		else {
			temp = temp->child[ch];
		}
	}
	return temp->wordcount;
}
int main()
{
	struct node *root = initialise();
	string s,s1,s2,t;
	map<string,string> m1;
	vector<string> v;
	int n;
	int m;
	int q;
	int i;

	cin>>n;
	cin>>s;
	cin>>m;
	for(i = 0; i < m; i++) {
		cin>>s1;
		s2 = s1;
		transform(s1.begin(), s1.end(), s1.begin(), ::tolower);
		m1[s1] = s2;
		reverse(s1.begin(),s1.end());
		root = addword(s1,root);
	}
	for(i = 0; i < n; i++) {
        t = t + s[i];
        //cout<<t<<' '<<wordcount(t,root)<<' '<<prefixcount(t,root)<<endl;
        if(wordcount(t,root) >= 1 && prefixcount(t,root) == 1) {
            reverse(t.begin(),t.end());
            v.push_back(t);
            t.clear();
        }
	}
	if(t.size() != 0) {
         reverse(t.begin(),t.end());
        v.push_back(t);
	}
	n = v.size();
	for(i = 0; i < n; i++) {
        cout<<m1[v[i]]<<' ';
	}

}


#include <bits/stdc++.h>
using namespace std;
struct node {
    int id;
	struct node *child[26];
};
struct node *initialise()
{
	struct node *newnode = (struct node *)malloc(sizeof(struct node));
	newnode->id = 0;
	for(int i = 0; i < 26; i++) {
		newnode->child[i] = NULL;
	}
	return newnode;
}
struct node *root = initialise();
struct node *addword(string s,int id,struct node *root)
{
	int i;
	int ch;
	struct node *temp = root;
	struct node *newnode = NULL;

	for(i = 0; i < s.size(); i++) {
		ch = s[i]-'a';

		if(temp->child[ch] == NULL) {
			newnode = initialise();
			temp->child[ch] = newnode;
			temp = temp->child[ch];
		}
		else {
			temp = temp->child[ch];
		}

	}
	temp->id = id+1;
	return root;
}
string s1[100005];
string s;
int len;
int h[100005];
int dp[100005];
vector<string> ans;
int f(int pos)
{
    struct node *temp = root;
    //cout<<pos<<endl;
    if(pos == len) {
        return 1;
    }

    if(dp[pos] != -1) {
        return dp[pos];
    }

    for(int i = pos; i < len; i++) {
        int ch = s[i]-'a';
        if(temp->child[ch] && temp->child[ch]->id && h[temp->child[ch]->id] == 0) {
            h[temp->child[ch]->id] = 1;
            if(f(i+1)) {
                ans.push_back(s1[temp->child[ch]->id-1]);
                dp[pos] = 1;
                return dp[pos];
            }
            else {
                h[temp->child[ch]->id] = 0;
                temp = temp->child[ch];
            }
        }
        else if(temp->child[ch]) {
            temp = temp->child[ch];
        }
        else {
            dp[pos] = 0;
            return dp[pos];
        }
    }
    dp[pos] = 0;
    return 0;

}
int main()
{

	string s2,t;
	vector<string> v;
	int n;
	int m;
	int q;
	int i;

	cin>>n;
	cin>>s;
	cin>>m;
	len = s.size();
	for(i = 0; i <= len; i++) {
        dp[i] = -1;
	}
	for(i = 0; i < m; i++) {
		cin>>s1[i];
		s2 = s1[i];
		transform(s2.begin(), s2.end(), s2.begin(), ::tolower);
		reverse(s2.begin(),s2.end());
		root = addword(s2,i,root);
	}
	f(0);
	for(i = ans.size()-1; i >= 0; i--) {
        cout<<ans[i]<<' ';
	}

}