#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

int main()
{
    char s[1002][1002];
    int i = 0, mx = 0;
    while(gets(s[i]))
    {
        mx = max(mx,(int)strlen(s[i]));
        i++;
    }
    for(int j = 1; j <= mx+2; j++)
    {
        printf ("*");
    }
    printf("\n");
    bool left = 1, right = 0;
    for(int j = 0; j < i; j++)
    {
        printf ("*");
        int len = strlen(s[j]);
        if((mx-len)%2==1){
        if(left==1)
        {
            for(int k = 1, z= 0; k <= mx; k++)
            {
                if(k <= (mx-len)/2) printf(" ");
                else if(k <= (mx+len)/2)
                {
                    printf("%c",s[j][z]);
                    z++;
                }
                else printf(" ");
            }
            left = 0;
            right = 1;
        }
        else
        {
            for(int k = 1, z= 0; k <= mx; k++)
            {
                if(k <= (mx-len+2)/2) printf(" ");
                else if(k <= (mx+len+2)/2)
                {
                    printf("%c",s[j][z]);
                    z++;
                }
                else printf(" ");
            }
            right = 0;
            left = 1;
        }
        }
        else{
            for(int k = 1, z= 0; k <= mx; k++)
            {
                if(k <= (mx-len)/2) printf(" ");
                else if(k <= (mx+len)/2)
                {
                    printf("%c",s[j][z]);
                    z++;
                }
                else printf(" ");
            }
        }
        printf("*\n");
    }
    for(int j = 1; j <= mx+2; j++)
    {
        printf ("*");
    }
    printf("\n");
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
typedef long long ll;
#define MD 1000000007
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
char s[1010][1010];
int main()
{
    //freopen("H:\\in.txt","r",stdin);
    //freopen("H:\\out.txt","w",stdout);
    int k = 0;
    int mmax = -1;
    while (gets(s[k]) != NULL)
    {
        mmax = max(mmax, (int)strlen(s[k]));
        k++;
    }
    for (int i = 0; i < mmax + 2; i++)
       printf("*");
    printf("\n");
    bool ok = true;
    for (int i = 0; i < k; i++)
    {
       printf("*");
        int flag = (mmax - strlen(s[i])) / 2;
        if ((mmax - strlen(s[i])) % 2 == 0)
        {
        for (int j = 0; j < flag; j++)
            printf(" ");
        printf("%s", s[i]);
        for (int j = 0; j < flag; j++)
            printf(" ");
        }
        else if (ok)
        {
            for (int j = 0; j < flag; j++)
            printf(" ");
        printf("%s", s[i]);
        for (int j = 0; j < flag + 1; j++)
            printf(" ");
        ok = false;
        }
        else
        {
            for (int j = 0; j < flag + 1; j++)
                printf(" ");
            printf("%s", s[i]);
            for (int j = 0; j < flag; j++)
                printf(" ");
            ok = true;
        }
       printf("*");
        printf("\n");
    }
    for (int i = 0; i < mmax + 2; i++)
        printf("*");
    printf("\n");
    return 0;
}


#include <iostream>
#include <string>
#include <cstdio>
#include <iostream>
#include <iostream>
using namespace std;

string ss [1010];

int main(){

    string s = "";
    int c = 0;
    int mx = 0;
    while( getline(cin,s) ){
        ss[c++] = s;
        mx = max(mx, s.size());
    }
    for( int i = 0; i < mx+2; i++ )
        printf("*");
    int z = 0;
    for( int i = 0; i < c; i++ ){
        printf("\n");
        printf("*");
        int q = (mx-s.size())/2,l,r;
        l = r = q;
        if( (mx-s.size())&1 ){
            l+=z;
            r+=1-z;
        }
        for( int j = 0; j < l; j++ ) printf(" ");
        printf("%s", ss[i].c_str());
        for( int j = 0; j < r; j++ ) printf(" ");
        printf("*");

    }
        printf("\n");
    for( int i = 0; i < mx+2; i++ )
        printf("*");
}


#include <iostream>
#include <string>
#include <iostream>
#include <iostream>
#include <iostream>
using namespace std;

string ss [1010];

int main(){

    string s = "";
    int c = 0;
    int mx = 0;
    while( getline(cin,s) ){
        ss[c++] = s;
        mx = max(mx, s.size());
    }
    for( int i = 0; i < mx+2; i++ )
        printf("*");
    int z = 0;
    for( int i = 0; i < c; i++ ){
        printf("\n");
        printf("*");
        int q = (mx-s.size())/2,l,r;
        l = r = q;
        if( (mx-s.size())&1 ){
            l+=z;
            r+=1-z;
        }
        for( int j = 0; j < l; j++ ) printf(" ");
        printf("%s", ss[i].c_str());
        for( int j = 0; j < r; j++ ) printf(" ");
        printf("*");

    }
        printf("\n");
    for( int i = 0; i < mx+2; i++ )
        printf("*");

    cout<<res;
}


#include <iostream>
#include <string>
#include <cstdio>
#include <iostream>
#include <iostream>
using namespace std;

string ss [1010];

int main(){

    string s = "";
    int c = 0;
    int mx = 0;
    while( getline(cin,s) ){
        ss[c++] = s;
        mx = max(mx, int(s.size()));
    }
    for( int i = 0; i < mx+2; i++ )
        printf("*");
    int z = 0;
    for( int i = 0; i < c; i++ ){
        printf("\n");
        printf("*");
        int q = (mx-s.size())/2,l,r;
        l = r = q;
        if( (mx-s.size())&1 ){
            l+=z&1;
            r+=1-(z&1);
            z++;
        }
        for( int j = 0; j < l; j++ ) printf(" ");
        printf("%s", ss[i].c_str());
        for( int j = 0; j < r; j++ ) printf(" ");
        printf("*");

    }
        printf("\n");
    for( int i = 0; i < mx+2; i++ )
        printf("*");
}


#include <iostream>
#include <string>
#include <cstdio>
#include <iostream>
#include <iostream>
using namespace std;

string ss [1010];

int main(){

    string s = "";
    int c = 0;
    int mx = 0;
    while( getline(cin,s) ){
        ss[c++] = s;
        mx = max(mx, int(s.size()));
    }
    for( int i = 0; i < mx+2; i++ )
        printf("*");
    int z = 0;
    for( int i = 0; i < c; i++ ){
        s=ss[i];
        printf("\n");
        printf("*");
        int q = (mx-s.size())/2,l,r;
        l = r = q;
        if( (mx-s.size())&1 ){
            l+=z;
            r+=1-z;
        }
        for( int j = 0; j < l; j++ ) printf(" ");
        printf("%s", ss[i].c_str());
        for( int j = 0; j < r; j++ ) printf(" ");
        printf("*");

    }
        printf("\n");
    for( int i = 0; i < mx+2; i++ )
        printf("*");
}


#include <iostream>
#include <string>
#include <cstdio>
#include <iostream>
#include <iostream>
using namespace std;

string ss [1010];

int main(){

    string s = "";
    int c = 0;
    int mx = 0;
    while( getline(cin,s) ){
        ss[c++] = s;
        mx = max(mx, int(s.size()));
    }
    for( int i = 0; i < mx+2; i++ )
        printf("*");
    int z = 0;
    for( int i = 0; i < c; i++ ){
        printf("\n");
        printf("*");
        int q = (mx-s.size())/2,l,r;
        l = r = q;
        if( (mx-s.size())&1 ){
            l+=z;
            r+=1-z;
        }
        for( int j = 0; j < l; j++ ) printf(" ");
        printf("%s", ss[i].c_str());
        for( int j = 0; j < r; j++ ) printf(" ");
        printf("*");

    }
        printf("\n");
    for( int i = 0; i < mx+2; i++ )
        printf("*");
}


#include <iostream>
#include <string>
#include <cstdio>
#include <iostream>
#include <iostream>
using namespace std;

string ss [1010];

int main(){

    string s = "";
    int c = 0;
    int mx = 0;
    while( getline(cin,s) ){
        ss[c++] = s;
        mx = max(mx, int(s.size()));
    }
    for( int i = 0; i < mx+2; i++ )
        printf("*");
    int z = 0;
    for( int i = 0; i < c; i++ ){
        s=ss[i];
        printf("\n");
        printf("*");
        int q = (mx-s.size())/2,l,r;
        l = r = q;
        if( (mx-s.size())&1 ){
            l+=(z&1);
            r+=1-(z&1);
            z++;
        }
        for( int j = 0; j < l; j++ ) printf(" ");
        printf("%s", ss[i].c_str());
        for( int j = 0; j < r; j++ ) printf(" ");
        printf("*");

    }
        printf("\n");
    for( int i = 0; i < mx+2; i++ )
        printf("*");
}


#include <iostream>
#include <string>
#include <cstdio>
#include <iostream>
#include <iostream>
using namespace std;

string ss [1010];

int main(){

    string s = "";
    int c = 0;
    int mx = 0;
    while( getline(cin,s) ){
        ss[c++] = s;
        mx = max(mx, s.size());
    }
    for( int i = 0; i < mx+2; i++ )
        printf("*");
    int z = 0;
    for( int i = 0; i < c; i++ ){
        printf("\n");
        printf("*");
        int q = (mx-s.size())/2,l,r;
        l = r = q;
        if( (mx-s.size())&1 ){
            l+=z;
            r+=1-z;
        }
        for( int j = 0; j < l; j++ ) printf(" ");
        printf("%s", ss[i].c_str());
        for( int j = 0; j < r; j++ ) printf(" ");
        printf("*");

    }
        printf("\n");
    for( int i = 0; i < mx+2; i++ )
        printf("*");

    cout<<res;
}


#include <stdio.h>
#include <string>
#include <iostream>

using namespace std;

int main()
{
	string s[1001];
	int n=1;
	while (getline(cin,s[n]))
	{
		n++;
		if (s[1]=="Cp") cout<<n<<" ";
	}
	n--;
	int max=0;

	for (int i=1;i<=n;i++)
		if (max<s[i].length()) max=s[i].length();

	for (int i=1;i<=max+2;i++) cout<<'*';
	cout<<"\n";
	bool kt=true;
	for (int i=1;i<=n;i++)
	{
		cout<<'*';
		int kdau=(max-s[i].length())/2;
		int kcuoi=max-kdau-s[i].length();
		if (kdau!=kcuoi)
		{
			if (kt==false)
			{
				kdau++;
				kcuoi--;
				kt=true;
			}
			else kt=false;
		}
		for (int j=1;j<=kdau;j++) cout<<' ';
		cout<<s[i];
		for (int j=1;j<=kcuoi;j++) cout<<' ';
		cout<<"*\n";
	}
	for (int i=1;i<=max+2;i++) cout<<'*';
}


#include <string>
#include <iostream>

using namespace std;

int main()
{
	string s[1005];
	int n=1;
	while (getline(cin,s[n]))
	{
		n++;
		if (n>1000) break;
	}
	n--;
	int max=0;
	for (int i=1;i<=n;i++)
		if (max<s[i].length()) max=s[i].length();
	for (int i=1;i<=max+2;i++) cout<<'*';
	cout<<"\n";
	bool kt=true;
	for (int i=1;i<=n;i++)
	{
		cout<<'*';
		int kdau=(max-s[i].length())/2;
		int kcuoi=max-kdau-s[i].length();
		if (kdau!=kcuoi)
		{
			if (kt==false)
			{
				kdau++;
				kcuoi--;
				kt=true;
			}
			else kt=false;
		}
		for (int j=1;j<=kdau;j++) cout<<' ';
		cout<<s[i];
		for (int j=1;j<=kcuoi;j++) cout<<' ';
		cout<<"*\n";
	}
	for (int i=1;i<=max+2;i++) cout<<'*';
}


#include <stdio.h>
#include <string>
#include <iostream>

using namespace std;

int main()
{
	string s[1001];
	int n;
	for (int i=1;i<=1000;i++) getline(cin,s[i]);
	for (int i=1000;i>=1;i--)
		if (s[i].length())
		{
			n=i;
			break;
		}
	int max=0;
	for (int i=1;i<=n;i++)
		if (max<s[i].length()) max=s[i].length();

	for (int i=1;i<=max+2;i++) cout<<'*';
	cout<<"\n";
	int kt=true;
	for (int i=1;i<=n;i++)
	{
		cout<<'*';
		int kdau=(max-s[i].length())/2;
		int kcuoi=max-kdau-s[i].length();
		if (kdau!=kcuoi)
		{
			if (kt==false)
			{
				kdau++;
				kcuoi--;
				kt=true;
			}
			else kt=false;
		}
		for (int j=1;j<=kdau;j++) cout<<' ';
		cout<<s[i];
		for (int j=1;j<=kcuoi;j++) cout<<' ';
		cout<<"*\n";
	}
	for (int i=1;i<=max+2;i++) cout<<'*';
}


#include <string>
#include <iostream>

using namespace std;

int main()
{
	string s[1001];
	int n=0;
	while (getline(cin,s[n])) n++;
	n--;
	if (s[1]=="Cp") cout<<n<<"1 ";
	int max=0;
	for (int i=1;i<=n;i++)
		if (max<s[i].length()) max=s[i].length();
	if (s[1]=="Cp") cout<<n<<"2 ";
	for (int i=1;i<=max+2;i++) cout<<'*';
	cout<<"\n";
	bool kt=true;
	for (int i=1;i<=n;i++)
	{
		cout<<'*';
		if (s[1]=="Cp") cout<<n<<"3 ";
		int kdau=(max-s[i].length())/2;
		int kcuoi=max-kdau-s[i].length();
		if (kdau!=kcuoi)
		{
			if (kt==false)
			{
				kdau++;
				kcuoi--;
				kt=true;
			}
			else kt=false;
		}
		for (int j=1;j<=kdau;j++) cout<<' ';
		cout<<s[i];
		for (int j=1;j<=kcuoi;j++) cout<<' ';
		cout<<"*\n";
	}
	for (int i=1;i<=max+2;i++) cout<<'*';
}


#include <stdio.h>
#include <string>
#include <iostream>

using namespace std;

int main()
{
	string s[1001];
	int n;
	for (int i=1;i<=1000;i++) getline(cin,s[i]);
	for (int i=1000;i>=1;i--)
		if (s[i].length())
		{
			n=i;
			break;
		}
	int max=0;
	for (int i=1;i<=n;i++)
		if (max<s[i].length()) max=s[i].length();

	for (int i=1;i<=max+2;i++) cout<<'*';
	cout<<"\n";
	for (int i=1;i<=n;i++)
	{
		cout<<'*';
		int kdau=(max-s[i].length())/2;
		int kcuoi=max-kdau-s[i].length();
		for (int j=1;j<=kdau;j++) cout<<' ';
		cout<<s[i];
		for (int j=1;j<=kcuoi;j++) cout<<' ';
		cout<<"*\n";
	}
	for (int i=1;i<=max+2;i++) cout<<'*';
}


#include <stdio.h>
#include <string>
#include <iostream>

using namespace std;

int main()
{
	string s[1001];
	int n=1;
	while (getline(cin,s[n])) n++;
	n--;
	if (s[1]=="Cp") cout<<n<<"1 ";
	int max=0;
	for (int i=1;i<=n;i++)
		if (max<s[i].length()) max=s[i].length();
	if (s[1]=="Cp") cout<<n<<"2 ";
	for (int i=1;i<=max+2;i++) cout<<'*';
	cout<<"\n";
	bool kt=true;
	for (int i=1;i<=n;i++)
	{
		cout<<'*';
		if (s[1]=="Cp") cout<<n<<"3 ";
		int kdau=(max-s[i].length())/2;
		int kcuoi=max-kdau-s[i].length();
		if (kdau!=kcuoi)
		{
			if (kt==false)
			{
				kdau++;
				kcuoi--;
				kt=true;
			}
			else kt=false;
		}
		for (int j=1;j<=kdau;j++) cout<<' ';
		cout<<s[i];
		for (int j=1;j<=kcuoi;j++) cout<<' ';
		cout<<"*\n";
	}
	for (int i=1;i<=max+2;i++) cout<<'*';
}


#include <stdio.h>
#include <string>
#include <iostream>

using namespace std;

int main()
{
	string s[1001];
	int n=1;
	while (getline(cin,s[n])) n++;
	int max=0;

	for (int i=1;i<=n;i++)
		if (max<s[i].length()) max=s[i].length();

	for (int i=1;i<=max+2;i++) cout<<'*';
	cout<<"\n";
	int kt=true;
	for (int i=1;i<=n;i++)
	{
		cout<<'*';
		int kdau=(max-s[i].length())/2;
		int kcuoi=max-kdau-s[i].length();
		if (kdau!=kcuoi)
		{
			if (kt==false)
			{
				kdau++;
				kcuoi--;
				kt=true;
			}
			else kt=false;
		}
		for (int j=1;j<=kdau;j++) cout<<' ';
		cout<<s[i];
		for (int j=1;j<=kcuoi;j++) cout<<' ';
		cout<<"*\n";
	}
	for (int i=1;i<=max+2;i++) cout<<'*';
}


#include <stdio.h>
#include <string>
#include <iostream>

using namespace std;

int main()
{
	string s[1001];
	int n=1;
	while (getline(cin,s[n])) n++;
	n--;
	int max=0;

	for (int i=1;i<=n;i++)
		if (max<s[i].length()) max=s[i].length();

	for (int i=1;i<=max+2;i++) cout<<'*';
	cout<<"\n";
	bool kt=true;
	for (int i=1;i<=n;i++)
	{
		cout<<'*';
		int kdau=(max-s[i].length())/2;
		int kcuoi=max-kdau-s[i].length();
		if (kdau!=kcuoi)
		{
			if (kt==false)
			{
				kdau++;
				kcuoi--;
				kt=true;
			}
			else kt=false;
		}
		for (int j=1;j<=kdau;j++) cout<<' ';
		cout<<s[i];
		for (int j=1;j<=kcuoi;j++) cout<<' ';
		cout<<"*\n";
	}
	for (int i=1;i<=max+2;i++) cout<<'*';
}


#include <stdio.h>
#include <string>
#include <iostream>

using namespace std;

int main()
{
	string s[1001];
	int n;
	for (int i=1;i<=1000;i++) getline(cin,s[i]);
	for (int i=1000;i>=1;i--)
		if (s[i].length())
		{
			n=i;
			break;
		}
	int max=0;
	for (int i=1;i<=n;i++)
		if (max<s[i].length()) max=s[i].length();

	for (int i=1;i<=max+2;i++) cout<<'*';
	cout<<"\n";
	for (int i=1;i<=n;i++)
	{
		cout<<'*';
		int kcuoi=(max-s[i].length())/2;
		int kdau=max-kdau-s[i].length();
		for (int j=1;j<=kdau;j++) cout<<' ';
		cout<<s[i];
		for (int j=1;j<=kcuoi;j++) cout<<' ';
		cout<<"*\n";
	}
	for (int i=1;i<=max+2;i++) cout<<'*';
}


#include <stdio.h>
#include <string>
#include <iostream>

using namespace std;

int main()
{
	string s[1001];
	int n=1;
	while (getline(cin,s[n])) n++;
	n--;
	int max=0;

	for (int i=1;i<=n;i++)
		if (max<s[i].length()) max=s[i].length();

	for (int i=1;i<=max+2;i++) cout<<'*';
	cout<<"\n";
	bool kt=true;
	for (int i=1;i<=n;i++)
	{
		cout<<'*';
		int kdau=(max-s[i].length())/2;
		int kcuoi=max-kdau-s[i].length();
		if (kdau!=kcuoi)
		{
			if (kt)
			{
				kdau++;
				kcuoi--;
				kt=true;
			}
			else kt=false;
		}
		for (int j=1;j<=kdau;j++) cout<<' ';
		cout<<s[i];
		for (int j=1;j<=kcuoi;j++) cout<<' ';
		cout<<"*\n";
	}
	for (int i=1;i<=max+2;i++) cout<<'*';
}


#include <stdio.h>
#include <string>
#include <iostream>

using namespace std;

int main()
{
	string s[1001];
	int n=1;
	while (getline(cin,s[n])) n++;
	n--;
	int max=0;

	for (int i=1;i<=n;i++)
		if (max<s[i].length()) max=s[i].length();

	for (int i=1;i<=max+2;i++) cout<<'*';
	cout<<"\n";
	int kt=true;
	for (int i=1;i<=n;i++)
	{
		cout<<'*';
		int kdau=(max-s[i].length())/2;
		int kcuoi=max-kdau-s[i].length();
		if (kdau!=kcuoi)
		{
			if (kt==false)
			{
				kdau++;
				kcuoi--;
				kt=true;
			}
			else kt=false;
		}
		for (int j=1;j<=kdau;j++) cout<<' ';
		cout<<s[i];
		for (int j=1;j<=kcuoi;j++) cout<<' ';
		cout<<"*\n";
	}
	for (int i=1;i<=max+2;i++) cout<<'*';
}


#include <stdio.h>
#include <string>
#include <iostream>

using namespace std;

int main()
{
	string s[1001];
	int n;
	for (int i=1;i<=1000;i++) getline(cin,s[i]);
	for (int i=1000;i>=1;i--)
		if (s[i].length())
		{
			n=i;
			break;
		}
	int max=0;
	for (int i=1;i<=n;i++)
		if (max<s[i].length()) max=s[i].length();

	for (int i=1;i<=max+2;i++) cout<<'*';
	cout<<"\n";
	for (int i=1;i<=n;i++)
	{
		cout<<'*';
		int kcuoi=(max-s[i].length())/2;
		int kdau=max-kcuoi-s[i].length();
		for (int j=1;j<=kdau;j++) cout<<' ';
		cout<<s[i];
		for (int j=1;j<=kcuoi;j++) cout<<' ';
		cout<<"*\n";
	}
	for (int i=1;i<=max+2;i++) cout<<'*';
}


#include <stdio.h>
#include <string>
#include <iostream>

using namespace std;

int main()
{
	string s[1001];
	int n;
	for (int i=1;i<=1000;i++) getline(cin,s[i]);
	for (int i=1000;i>=1;i--)
		if (s[i].length())
		{
			n=i;
			break;
		}
	int max=0;
	for (int i=1;i<=n;i++)
		if (max<s[i].length()) max=s[i].length();

	for (int i=1;i<=max+2;i++) cout<<'*';
	cout<<"\n";
	for (int i=1;i<=n;i++)
	{
		cout<<'*';
		int kdau=(max-s[i].length())/2;
		int kcuoi=max-kdau-s[i].length();
		bool kt=true;
		if (kdau!=kcuoi)
		{
			if (kt==false)
			{
				kdau--;
				kcuoi++;
				kt=true;
			}
			else kt=false;
		}
		for (int j=1;j<=kdau;j++) cout<<' ';
		cout<<s[i];
		for (int j=1;j<=kcuoi;j++) cout<<' ';
		cout<<"*\n";
	}
	for (int i=1;i<=max+2;i++) cout<<'*';
}


#include <stdio.h>
#include <string>
#include <iostream>

using namespace std;

int main()
{
	string s[1001];
	int n;
	for (int i=1;i<=6;i++) getline(cin,s[i]);
	for (int i=1000;i>=1;i--)
		if (s[i].length())
		{
			n=i;
			break;
		}
	int max=0;
	for (int i=1;i<=n;i++)
		if (max<s[i].length()) max=s[i].length();

	for (int i=1;i<=max+2;i++) cout<<'*';
	cout<<"\n";
	int kt=true;
	for (int i=1;i<=n;i++)
	{
		cout<<'*';
		int kdau=(max-s[i].length())/2;
		int kcuoi=max-kdau-s[i].length();
		if (kdau!=kcuoi)
		{
			if (kt==false)
			{
				kdau++;
				kcuoi--;
				kt=true;
			}
			else kt=false;
		}
		for (int j=1;j<=kdau;j++) cout<<' ';
		cout<<s[i];
		for (int j=1;j<=kcuoi;j++) cout<<' ';
		cout<<"*\n";
	}
	for (int i=1;i<=max+2;i++) cout<<'*';
}


#include<bits/stdc++.h>
using namespace std;
vector<char>V[1111];
char a;
int sayac=0,maxi;
int main()
{
	while(scanf("%c",&a)!=EOF)
	{
		if(a=='\n')
		{
			sayac++;
		}
		else V[sayac].push_back(a);
		if((int)V[sayac].size()>maxi)
		maxi=(int)V[sayac].size();
	}
	for(int i=1;i<=maxi+2;i++) printf("*");
	printf("\n");
	int nere=0;
	for(int i=0;i<sayac;i++)
	{
		int bir=0 ,iki=0;
		if((int)V[i].size()%2!=maxi%2 && (int)V[i].size()<maxi)
		{
			nere++;
		if(nere%2) bir=1;
		else iki=1;
		}
		printf("*");
		for(int j=1;j<=(maxi-(int)V[i].size())/2+iki;j++)
		printf(" ");
		for(int j=0;j<(int)V[i].size();j++)
		printf("%c",V[i][j]);
		for(int j=1;j<=(maxi-(int)V[i].size())/2+bir;j++)
		printf(" ");
		printf("*\n");
	}

	for(int i=1;i<=maxi+2;i++) printf("*");

}


#include<bits/stdc++.h>
using namespace std;
vector<char>V[1111];
char a;
int sayac=0,maxi;
int main()
{
	while(scanf("%c",&a)!=EOF)
	{
		if(a=='\n')
		{
			sayac++;
		}
		else V[sayac].push_back(a);
		if((int)V[sayac].size()>maxi)
		maxi=(int)V[sayac].size();
	}
	for(int i=1;i<=maxi+2;i++) printf("*");
	printf("\n");
	int nere=0;
	for(int i=0;i<sayac;i++)
	{
		int bir=0 ,iki=0;
		if((int)V[i].size()%2==1)
		{
			nere++;
		if(nere%2 && (int)V[i].size()<maxi) bir=1;
		else if((int)V[i].size()<maxi) iki=1;
		}
		printf("*");
		for(int j=1;j<=(maxi-(int)V[i].size())/2+iki;j++)
		printf(" ");
		for(int j=0;j<(int)V[i].size();j++)
		printf("%c",V[i][j]);
		for(int j=1;j<=(maxi-(int)V[i].size())/2+bir;j++)
		printf(" ");
		printf("*\n");
	}

	for(int i=1;i<=maxi+2;i++) printf("*");

}


#include<bits/stdc++.h>
using namespace std;
vector<char>V[1111];
char a;
int sayac=0,maxi;
int main()
{
	while(scanf("%c",&a)!=EOF)
	{
		if(a=='\n')
		{
			sayac++;
		}
		else V[sayac].push_back(a);
		if((int)V[sayac].size()>maxi)
		maxi=(int)V[sayac].size();
	}
	for(int i=1;i<=maxi+2;i++) printf("*");
	printf("\n");
	int nere=0;
	for(int i=0;i<sayac;i++)
	{
		int bir=0 ,iki=0;
		if((int)V[i].size()%2==maxi%2 && (int)V[i].size()<maxi)
		{
			nere++;
		if(nere%2) bir=1;
		else iki=1;
		}
		printf("*");
		for(int j=1;j<=(maxi-(int)V[i].size())/2+iki;j++)
		printf(" ");
		for(int j=0;j<(int)V[i].size();j++)
		printf("%c",V[i][j]);
		for(int j=1;j<=(maxi-(int)V[i].size())/2+bir;j++)
		printf(" ");
		printf("*\n");
	}

	for(int i=1;i<=maxi+2;i++) printf("*");

}


#include<bits/stdc++.h>
using namespace std;
vector<char>V[1111];
char a;
int sayac=0,maxi;
int main()
{
	while(scanf("%c",&a)!=EOF)
	{
		if(a=='\n')
		{
			sayac++;
		}
		else V[sayac].push_back(a);
		if((int)V[sayac].size()>maxi)
		maxi=(int)V[sayac].size();
	}
	for(int i=1;i<=maxi+2;i++) printf("*");
	printf("\n");
	for(int i=0;i<sayac;i++)
	{
		printf("*");
		for(int j=1;j<=(maxi-(int)V[i].size())/2;j++)
		printf(" ");
		for(int j=0;j<(int)V[i].size();j++)
		printf("%c",V[i][j]);
		for(int j=1;j<=(maxi-(int)V[i].size())/2+(int)V[i].size()%2?1:0;j++)
		printf(" ");
		printf("*\n");
	}

	for(int i=1;i<=maxi+2;i++) printf("*");

}


#include<bits/stdc++.h>
using namespace std;
vector<char>V[1111];
char a;
int sayac=0,maxi;
int main()
{
	while(scanf("%c",&a)!=EOF)
	{
		if(a=='\n')
		{
			sayac++;
		}
		else V[sayac].push_back(a);
		if((int)V[sayac].size()>maxi)
		maxi=(int)V[sayac].size();
	}
	for(int i=1;i<=maxi+2;i++) printf("*");
	printf("\n");
	int nere=0;
	for(int i=0;i<sayac;i++)
	{
		int bir=0 ,iki=0;
		if((int)V[i].size()%2==1 && (int)V[i].size()<maxi)
		{
			nere++;
		if(nere%2) bir=1;
		else iki=1;
		}
		printf("*");
		for(int j=1;j<=(maxi-(int)V[i].size())/2+iki;j++)
		printf(" ");
		for(int j=0;j<(int)V[i].size();j++)
		printf("%c",V[i][j]);
		for(int j=1;j<=(maxi-(int)V[i].size())/2+bir;j++)
		printf(" ");
		printf("*\n");
	}

	for(int i=1;i<=maxi+2;i++) printf("*");

}


#include<bits/stdc++.h>
using namespace std;
vector<char>V[1111];
char a;
int sayac=0,maxi;
int main()
{
	while(scanf("%c",&a)!=EOF)
	{
		if(a=='\n')
		{
			sayac++;
		}
		else V[sayac].push_back(a);
		if((int)V[sayac].size()>maxi)
		maxi=(int)V[sayac].size();
	}
	for(int i=1;i<=maxi+2;i++) printf("*");
	printf("\n");
	int nere=0;
	for(int i=0;i<sayac;i++)
	{
		int bir=0 ,iki=0;
		if((int)V[i].size()%2==1)
		{
			nere++;
		if(nere%2) bir=1;
		else iki=1;
		}
		printf("*");
		for(int j=1;j<=(maxi-(int)V[i].size())/2+bir;j++)
		printf(" ");
		for(int j=0;j<(int)V[i].size();j++)
		printf("%c",V[i][j]);
		for(int j=1;j<=(maxi-(int)V[i].size())/2+iki;j++)
		printf(" ");
		printf("*\n");
	}

	for(int i=1;i<=maxi+2;i++) printf("*");

}


#include<bits/stdc++.h>
using namespace std;
vector<char>V[1111];
char a;
int sayac=0,maxi;
int main()
{
	while(scanf("%c",&a)!=EOF)
	{
		if(a=='\n')
		{
			sayac++;
		}
		else V[sayac].push_back(a);
		if((int)V[sayac].size()>maxi)
		maxi=(int)V[sayac].size();
	}
	for(int i=1;i<=maxi+2;i++) printf("*");
	printf("\n");
	int nere=0;
	for(int i=0;i<sayac;i++)
	{
		int bir=0 ,iki=0;
		if((int)V[i].size()%2==1)
		{
			nere++;
		if(nere%2) bir=1;
		else iki=1;
		}
		printf("*");
		for(int j=1;j<=(maxi-(int)V[i].size())/2+iki;j++)
		printf(" ");
		for(int j=0;j<(int)V[i].size();j++)
		printf("%c",V[i][j]);
		for(int j=1;j<=(maxi-(int)V[i].size())/2+bir;j++)
		printf(" ");
		printf("*\n");
	}

	for(int i=1;i<=maxi+2;i++) printf("*");

}


#include<bits/stdc++.h>
using namespace std;
vector<char>V[1111];
char a;
int sayac=0,maxi;
int main()
{
	while(scanf("%c",&a)!=EOF)
	{
		if(a=='\n')
		{
			sayac++;
		}
		else V[sayac].push_back(a);
		if((int)V[sayac].size()>maxi)
		maxi=(int)V[sayac].size();
	}
	for(int i=1;i<=maxi+2;i++) printf("*");
	printf("\n");
	for(int i=0;i<sayac;i++)
	{
		printf("*");
		for(int j=1;j<=(maxi-(int)V[i].size())/2+(int)V[i].size()%2?1:0;j++)
		printf(" ");
		for(int j=0;j<(int)V[i].size();j++)
		printf("%c",V[i][j]);
		for(int j=1;j<=(maxi-(int)V[i].size())/2;j++)
		printf(" ");
		printf("*\n");
	}

	for(int i=1;i<=maxi+2;i++) printf("*");

}


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char s[1111][1111];
int l[1111];
int main()
{
    int top=0,m=0;
    while(gets(s[top])!=NULL)
    {
        l[top]=strlen(s[top]);
        m=max(m,l[top]);
        top++;
    }
    m+=2;
    for(int i=0;i<m;i++)
        printf("*");
    puts("");
    int t,flag=0;
    for(int i=0;i<top;i++)
    {
        int a=(m-2-l[i])/2,b;
        b=a;
        if(a*2!=m-2-l[i])
            b++;
        if(flag==0&&a!=b)
            flag=1;
        else if(flag==1&&a!=b)
        {
            t=a;a=b;b=t;
            flag=0;
        }
        printf("*");
        for(int i=0;i<a;i++)
            printf(" ");
        printf("%s",s[i]);
        for(int i=0;i<b;i++)
            printf(" ");
        puts("*");
    }
    for(int i=0;i<m;i++)
        printf("*");
    puts("");
    return 0;
}
/*2018-08-09 09:57:49.806*/


#include<stdio.h>
#include<string.h>
char s[1002][1002];
int main()
{
    int cnt=0,flag=0,ans=-1,i,j,t;
    while(gets(s[cnt]))
    {

        ans=(int)strlen(s[cnt])>ans?(int)strlen(s[cnt]):ans;
        cnt++;
    }
    printf("%d %d\n",cnt,ans);
    for(i=0;i<ans+2;i++)
        printf("*");
    printf("\n");
    for(i=0;i<cnt;i++)
    {
        printf("*");
        t=ans-(int)strlen(s[i]);
        //printf("%d %d\n",t/2,t-t/2);
        if(flag==0)
        {
            for(j=0;j<t/2;j++)
                printf(" ");
            printf("%s",s[i]);
            for(j=0;j<(t-t/2);j++)
                printf(" ");
                if(t%2!=0)
                flag=!flag;

        }
        else
        {
            for(j=0;j<(t-t/2);j++)
                printf(" ");
            printf("%s",s[i]);
            for(j=0;j<t/2;j++)
                printf(" ");
            if(t%2!=0)
            flag=!flag;
        }
        printf("*\n");

    }
        for(i=0;i<ans+2;i++)
        printf("*");
        return 0;
}/*2017-07-04 16:41:23.946*/


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char s[1111][1111];
int l[1111];
int main()
{
    int top=0,m=0;
    while(gets(s[top])!=NULL)
    {
        l[top]=strlen(s[top]);
        m=max(m,l[top]);
        top++;
    }
    m+=2;
    for(int i=0;i<m;i++)
        printf("*");
    puts("");
    for(int i=0;i<top;i++)
    {
        int a=(m-2-l[i])/2,b;
        b=a;
        if(a*2!=m-2-l[i])
            b++;
        printf("*");
        for(int i=0;i<a;i++)
            printf(" ");
        printf("%s",s[i]);
        for(int i=0;i<b;i++)
            printf(" ");
        puts("*");
    }
    for(int i=0;i<m;i++)
        printf("*");
    puts("");
    return 0;
}
/*2018-08-09 09:39:34.162*/


#include <iostream>
#include <unordered_map>
#include <stack>
#include <windows.h>
using namespace std;
/////////
stack<string> st;

struct Trie
{
    int words;
    string word;
    Trie *edges[26];
    Trie()
    {
        words = 0;
        for (int i = 0; i < 26; i++)
            edges[i] = NULL;
    }
} *root;

void addWord(string &w, Trie *t)
{
    char letter;
    for (int i = 0; i < w.size(); i++)
    {
        letter = tolower(w[i]);
        if (t->edges[letter - 'a'] == NULL)
            t->edges[letter - 'a'] = new Trie();
        t = t->edges[letter - 'a'];
    }

    t->words++;
    t->word = w;
}

void dfs(int index, string &s, Trie *t)
{
    if (index == -1)
    {
        if (t == root)
        {
            while (!st.empty())
            {
                cout << st.top() << ' ';
                st.pop();
            }
            exit(0);
        }
        return;
    }

    if (t->edges[s[index] - 'a'] == NULL)
        return;
    t = t->edges[s[index] - 'a'];

    if (t->words)
    {
        st.push(t->word);
        dfs(index - 1, s, root);
        st.pop();
    }

    dfs(index - 1, s, t);
}

int main()
{
    int n, m, i, j;
    cin >> n;
    string s, text, l, current;
    cin >> text >> m;
    root = new Trie();
    for (i = 0; i < m; i++)
    {
        cin >> s;
        addWord(s, root);
    }

    dfs(text.size() - 1, text, root);
    return 0;
}


#include <iostream>
#include <unordered_map>
#include <stack>
using namespace std;

unordered_map<string, string> h;
string w;
string text;
stack<string> result;

void dfs(int i)
{
    if (i == -1)
    {
        if (w == "")
        {
            while (!result.empty())
            {
                cout << h[result.top()] << ' ';
                result.pop();
            }
            exit(0);
        }
        return;
    }
    w += text[i];
    if (h[w] != "")
    {
        result.push(w);
        w = "";
        dfs(i - 1);
        stack<string> s2(result);
        while (!s2.empty())
            w += s2.top(), s2.pop();
        result.pop();
        dfs(i - 1);
    }
    else
        dfs(i - 1);
    w.pop_back();
}

int main()
{
    int n, m, i, j;
    cin >> n;
    string s, l;
    cin >> text >> m;
    for (i = 0; i < m; i++)
    {
        cin >> s;
        l = "";
        for (j = 0; j < s.size(); j++)
            l += tolower(s[j]);
        h[l] = s;
    }

    dfs(text.size() - 1);
    return 0;
}


#include <iostream>
#include <unordered_map>
#include <stack>
using namespace std;

unordered_map<string, string> h;
string w;
string text;
stack<string> result;

void dfs(int i)
{
    if (i == -1)
    {
        if (w == "")
        {
            while (!result.empty())
            {
                cout << h[result.top()] << ' ';
                result.pop();
            }
            exit(0);
        }
        return;
    }

    w += text[i];
    if (h[w] != "")
    {
        result.push(w);
        w = "";
        dfs(i - 1);
        w = text[i] + w;
        result.pop();
        dfs(i - 1);
    }
    else
        dfs(i - 1);
    w.pop_back();
}

int main()
{
    int n, m, i, j;
    cin >> n;
    string s, l;
    cin >> text >> m;
    for (i = 0; i < m; i++)
    {
        cin >> s;
        l = "";
        for (j = 0; j < s.size(); j++)
            l += tolower(s[j]);
        h[l] = s;
    }

    dfs(text.size() - 1);
    return 0;
}


#include <iostream>
#include <unordered_map>
#include <stack>
using namespace std;

stack<string> st;
unordered_map<string, string> h;

struct Trie
{
    int words;
    Trie *edges[26];
    Trie()
    {
        words = 0;
        for (int i = 0; i < 26; i++)
            edges[i] = NULL;
    }
} root;

void addWord(int index, string &w, Trie *t)
{
    if (t->edges[w[index] - 'a'] == NULL)
        t->edges[w[index] - 'a'] = new Trie();

    t = t->edges[w[index] - 'a'];
    if (index == w.size() - 1)
        t->words++;
    else
        addWord(index + 1, w, t);
}

void dfs(int index, string &current, string &s, Trie *t)
{
    if (index == -1 && current == "")
    {
        while (!st.empty())
        {
            cout << h[st.top()] << ' ';
            st.pop();
        }
        exit(0);
    }

    if (t->edges[s[index] - 'a'] == NULL)
        return;
    t = t->edges[s[index] - 'a'];
    current += s[index];

    if (t->words)
    {
        st.push(current);
        current = "";
        dfs(index - 1, current, s, &root);
        current = st.top();
        st.pop();
        dfs(index - 1, current, s, t);
    }
    else
    {
        dfs(index - 1, current, s, t);
        current.pop_back();
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    int n, m, i, j;
    cin >> n;
    string s, text, l, current;
    cin >> text >> m;
    for (i = 0; i < m; i++)
    {
        cin >> s;
        l = "";
        for (j = 0; j < s.size(); j++)
            l += tolower(s[j]);
        h[l] = s;
        addWord(0, l, &root);
    }

    dfs(text.size() - 1, current, text, &root);
    return 0;
}


#include <iostream>
#include <unordered_map>
#include <stack>
using namespace std;

stack<string> st;
unordered_map<string, string> h;

struct Trie
{
    int words;
    Trie *edges[26];
    Trie()
    {
        words = 0;
        for (int i = 0; i < 26; i++)
            edges[i] = NULL;
    }
} root;

void addWord(int index, string &w, Trie *t)
{
    if (t->edges[w[index] - 'a'] == NULL)
        t->edges[w[index] - 'a'] = new Trie();

    t = t->edges[w[index] - 'a'];
    if (index == w.size() - 1)
        t->words++;
    else
        addWord(index + 1, w, t);
}

void dfs(int index, string &current, string &s, Trie *t)
{
    if (index == -1 && current == "")
    {
        while (!st.empty())
        {
            cout << h[st.top()] << ' ';
            st.pop();
        }
        exit(0);
    }

    if (t->edges[s[index] - 'a'] == NULL)
        return;
    t = t->edges[s[index] - 'a'];
    current += s[index];

    if (t->words)
    {
        st.push(current);
        current = "";
        dfs(index - 1, current, s, &root);
        current = st.top();
        st.pop();
        dfs(index - 1, current, s, t);
    }
    else
        dfs(index - 1, current, s, t);

    current.pop_back();
}

int main()
{
    ios_base::sync_with_stdio(false);
    int n, m, i, j;
    cin >> n;
    string s, text, l, current;
    cin >> text >> m;
    for (i = 0; i < m; i++)
    {
        cin >> s;
        l = "";
        for (j = 0; j < s.size(); j++)
            l += tolower(s[j]);
        h[l] = s;
        addWord(0, l, &root);
    }

    dfs(text.size() - 1, current, text, &root);
    return 0;
}


#include <iostream>
#include <unordered_map>
#include <stack>
using namespace std;

unordered_map<string, string> h;
string w;
string text;
stack<string> result;

void dfs(int i)
{
    if (i == -1)
    {
        if (w == "")
        {
            while (!result.empty())
            {
                cout << h[result.top()] << ' ';
                result.pop();
            }
            exit(0);
        }
        return;
    }
    w += text[i];
    if (h.count(w))
    {
        result.push(w);
        w = "";
        dfs(i - 1);
        /*stack<string> s2(result);
        while (!s2.empty())
            w += s2.top(), s2.pop();*/
        w = result.top();
        result.pop();
        dfs(i - 1);
    }
    else
        dfs(i - 1);
    w.pop_back();
}

int main()
{
    int n, m, i, j;
    cin >> n;
    string s, l;
    cin >> text >> m;
    for (i = 0; i < m; i++)
    {
        cin >> s;
        l = "";
        for (j = 0; j < s.size(); j++)
            l += tolower(s[j]);
        h[l] = s;
    }

    dfs(text.size() - 1);
    return 0;
}


#include <iostream>
#include <unordered_map>
#include <stack>
using namespace std;

stack<string> st;
unordered_map<string, string> h;
string current, s;

struct Trie
{
    int words;
    Trie *edges[26];
    Trie()
    {
        words = 0;
        for (int i = 0; i < 26; i++)
            edges[i] = NULL;
    }
} root;

void addWord(int index, string &w, Trie *t)
{
    if (t->edges[w[index] - 'a'] == NULL)
        t->edges[w[index] - 'a'] = new Trie();

    t = t->edges[w[index] - 'a'];
    if (index == w.size() - 1)
        t->words++;
    else
        addWord(index + 1, w, t);
}

void dfs(int index, Trie *t)
{
    if (index == -1)
    {
        if (current == "")
        {
            while (!st.empty())
            {
                cout << h[st.top()] << ' ';
                st.pop();
            }
            exit(0);
        }
        return;
    }

    if (t->edges[s[index] - 'a'] == NULL)
        return;
    t = t->edges[s[index] - 'a'];
    current += s[index];

    if (t->words)
    {
        st.push(current);
        current = "";
        dfs(index - 1, &root);
        current = st.top();
        st.pop();
        dfs(index - 1, t);
    }
    else
    {
        dfs(index - 1, t);
        current.pop_back();
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    int n, m, i, j;
    cin >> n;
    string s, text, l, current;
    cin >> text >> m;
    ::s = text;
    for (i = 0; i < m; i++)
    {
        cin >> s;
        l = "";
        for (j = 0; j < s.size(); j++)
            l += tolower(s[j]);
        h[l] = s;
        addWord(0, l, &root);
    }

    dfs(text.size() - 1, &root);
    return 0;
}


#include <iostream>
#include <unordered_map>
#include <stack>
using namespace std;
/////////
stack<string> st;

struct Trie
{
    int words;
    string word;
    Trie *edges[26];
    Trie()
    {
        words = 0;
        for (int i = 0; i < 26; i++)
            edges[i] = NULL;
    }
} root;

void addWord(string &w, Trie *t)
{
    char letter;
    for (int i = 0; i < w.size(); i++)
    {
        letter = tolower(w[i]);
        if (t->edges[letter - 'a'] == NULL)
            t->edges[letter - 'a'] = new Trie();
        t = t->edges[letter - 'a'];
    }

    t->words++;
    t->word = w;
}

void dfs(int index, string &s, Trie *t)
{
    if (index == -1)
    {
        if (t == &root)
        {
            while (!st.empty())
            {
                cout << st.top() << ' ';
                st.pop();
            }
            exit(0);
        }
        return;
    }

    if (t->edges[s[index] - 'a'] == NULL)
        return;
    t = t->edges[s[index] - 'a'];

    if (t->words)
    {
        st.push(t->word);
        dfs(index - 1, s, &root);
        st.pop();
    }

    dfs(index - 1, s, t);
}

int main()
{
    int n, m, i, j;
    cin >> n;
    string s, text, l, current;
    cin >> text >> m;
    for (i = 0; i < m; i++)
    {
        cin >> s;
        addWord(s, &root);
    }

    dfs(text.size() - 1, text, &root);
    return 0;
}


#include <iostream>
#include <map>
#include <stack>
using namespace std;

stack<string> st;
map<string, string> h;

struct Trie
{
    int words;
    Trie *edges[26];
    Trie()
    {
        words = 0;
        for (int i = 0; i < 26; i++)
            edges[i] = NULL;
    }
} root;

void addWord(int index, string &w, Trie *t)
{
    if (t->edges[w[index] - 'a'] == NULL)
        t->edges[w[index] - 'a'] = new Trie();

    t = t->edges[w[index] - 'a'];
    if (index == w.size() - 1)
        t->words++;
    else
        addWord(index + 1, w, t);
}

void dfs(int index, string &current, string &s, Trie *t)
{
    if (index == -1)
    {
        if (current == "")
        {
            while (!st.empty())
            {
                cout << h[st.top()] << ' ';
                st.pop();
            }
            exit(0);
        }
        return;
    }

    if (t->edges[s[index] - 'a'] == NULL)
        return;
    t = t->edges[s[index] - 'a'];
    current += s[index];

    if (t->words)
    {
        st.push(current);
        current = "";
        dfs(index - 1, current, s, &root);
        current = st.top();
        st.pop();
        dfs(index - 1, current, s, t);
    }
    else
    {
        dfs(index - 1, current, s, t);
        current.pop_back();
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    int n, m, i, j;
    cin >> n;
    string s, text, l, current;
    cin >> text >> m;
    for (i = 0; i < m; i++)
    {
        cin >> s;
        l = "";
        for (j = 0; j < s.size(); j++)
            l += tolower(s[j]);
        h[l] = s;
        addWord(0, l, &root);
    }

    dfs(text.size() - 1, current, text, &root);
    return 0;
}


#include <iostream>
#include <unordered_map>
#include <stack>
using namespace std;

stack<string> st;

struct Trie
{
    int words;
    string word;
    Trie *edges[26];
    Trie()
    {
        words = 0;
        for (int i = 0; i < 26; i++)
            edges[i] = NULL;
    }
} root;

void addWord(string &w, Trie *t)
{
    char letter;
    for (int i = 0; i < w.size(); i++)
    {
        letter = tolower(w[i]);
        if (t->edges[letter - 'a'] == NULL)
            t->edges[letter - 'a'] = new Trie();
        t = t->edges[letter - 'a'];
    }

    t->words++;
    t->word = w;
}

void dfs(int index, string &s, Trie *t)
{
    if (index == -1)
    {
        if (t == &root)
        {
            while (!st.empty())
            {
                cout << st.top() << ' ';
                st.pop();
            }
            exit(0);
        }
        return;
    }

    if (t->edges[s[index] - 'a'] == NULL)
        return;
    t = t->edges[s[index] - 'a'];

    if (t->words)
    {
        st.push(t->word);
        dfs(index - 1, s, &root);
        st.pop();
    }

    dfs(index - 1, s, t);
}

int main()
{
    int n, m, i, j;
    cin >> n;
    string s, text, l, current;
    cin >> text >> m;
    for (i = 0; i < m; i++)
    {
        cin >> s;
        addWord(s, &root);
    }

    dfs(text.size() - 1, text, &root);
    return 0;
}


#include <iostream>
#include <unordered_map>
#include <stack>
using namespace std;
/////////
stack<string> st;

struct Trie
{
    string word;
    Trie *edges[26];
    Trie()
    {
        word = "";
        for (int i = 0; i < 26; i++)
            edges[i] = NULL;
    }
} *root;

void addWord(string &w, Trie *t)
{
    char letter;
    for (int i = 0; i < w.size(); i++)
    {
        letter = tolower(w[i]);
        if (t->edges[letter - 'a'] == NULL)
            t->edges[letter - 'a'] = new Trie();
        t = t->edges[letter - 'a'];
    }

    if (t->word.empty())
        t->word = w;
}

void dfs(int index, string &s, Trie *t)
{
    if (index == -1)
    {
        if (t == root)
        {
            while (!st.empty())
            {
                cout << st.top() << ' ';
                st.pop();
            }
            exit(0);
        }
        return;
    }

    if (t->edges[s[index] - 'a'] == NULL)
        return;
    t = t->edges[s[index] - 'a'];

    if (!t->word.empty())
    {
        st.push(t->word);
        dfs(index - 1, s, root);
        st.pop();
    }

    dfs(index - 1, s, t);
}

int main()
{
    ios_base::sync_with_stdio(false);
    int n, m, i, j;
    cin >> n;
    string s, text, l, current;
    cin >> text >> m;

    root = new Trie();
    for (i = 0; i < m; i++)
    {
        cin >> s;
        addWord(s, root);
    }

    dfs(text.size() - 1, text, root);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    printf("Hello world!\n");
    int *p = (int *)malloc(sizeof(int));
    scanf("%d", p);
    printf("%d", *p);
    return 0;
}


#include <iostream>
#include <unordered_map>
#include <stack>
using namespace std;

unordered_map<string, string> h;
string w;
string text;
stack<string> result;

void dfs(int i)
{
    if (i == -1)
    {
        if (w == "")
        {
            while (!result.empty())
            {
                cout << h[result.top()] << ' ';
                result.pop();
            }
            exit(0);
        }
        return;
    }

    w += text[i];
    if (w == "osinghatesheandchildishiskira")
        cout << h[w];
    if (h[w] != "")
    {
        result.push(w);
        w = "";
        dfs(i - 1);
        w = text[i] + w;
        dfs(i - 1);
    }
    else
        dfs(i - 1);
    w.pop_back();
}

int main()
{
    int n, m, i, j;
    cin >> n;
    string s, l;
    cin >> text >> m;
    for (i = 0; i < m; i++)
    {
        cin >> s;
        l = "";
        for (j = 0; j < s.size(); j++)
            l += tolower(s[j]);
        h[l] = s;
    }

    dfs(text.size() - 1);
    return 0;
}


#include <iostream>
#include <unordered_map>
#include <stack>
using namespace std;
/////////
stack<string> st;

struct Trie
{
    string word;
    Trie *edges[26];
    Trie()
    {
        word = "";
        for (int i = 0; i < 26; i++)
            edges[i] = NULL;
    }
} *root;

void addWord(string &w, Trie *t)
{
    char letter;
    for (int i = 0; i < w.size(); i++)
    {
        letter = tolower(w[i]);
        if (t->edges[letter - 'a'] == NULL)
            t->edges[letter - 'a'] = new Trie();
        t = t->edges[letter - 'a'];
    }

    if (t->word.empty())
        t->word = w;
}

void dfs(int index, string &s, Trie *t)
{
    if (index == -1)
    {
        if (t == root)
        {
            while (!st.empty())
            {
                cout << st.top() << ' ';
                st.pop();
            }
            exit(0);
        }
        return;
    }

    if (t->edges[s[index] - 'a'] == NULL)
        return;
    t = t->edges[s[index] - 'a'];

    if (!t->word.empty())
    {
        st.push(t->word);
        dfs(index - 1, s, root);
        st.pop();
    }

    dfs(index - 1, s, t);
}

int main()
{
    int n, m, i, j;
    cin >> n;
    string s, text, l, current;
    cin >> text >> m;
    for (i = 0; i < text.size(); i++)
    {
        if ((i + 1) % 50 == 0)
            cerr << '\n';
        cerr << text[i];
    }

    root = new Trie();
    for (i = 0; i < m; i++)
    {
        cin >> s;
        addWord(s, root);
    }

    dfs(text.size() - 1, text, root);
    return 0;
}


#include <iostream>
#include <unordered_map>
#include <stack>
using namespace std;

stack<string> st;
unordered_map<string, string> h;

struct Trie
{
    int words;
    string word;
    Trie *edges[26];
    Trie()
    {
        words = 0;
        for (int i = 0; i < 26; i++)
            edges[i] = NULL;
    }
} root;

void addWord(string &w, Trie *t)
{
    char letter;
    for (int i = 0; i < w.size(); i++)
    {
        letter = tolower(w[i]);
        if (t->edges[letter - 'a'] == NULL)
            t->edges[letter - 'a'] = new Trie();
        t = t->edges[letter - 'a'];
    }

    t->words++;
    t->word = w;
}

void dfs(int index, string &s, Trie *t)
{
    if (index == -1)
    {
        if (t == &root)
        {
            while (!st.empty())
            {
                cout << st.top() << ' ';
                st.pop();
            }
            exit(0);
        }
        return;
    }

    if (t->edges[s[index] - 'a'] == NULL)
        return;
    t = t->edges[s[index] - 'a'];

    if (t->words)
    {
        st.push(t->word);
        dfs(index - 1, s, &root);
        st.pop();
        dfs(index - 1, s, t);
    }
    else
    {
        dfs(index - 1, s, t);
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    int n, m, i, j;
    cin >> n;
    string s, text, l, current;
    cin >> text >> m;
    for (i = 0; i < m; i++)
    {
        cin >> s;
        addWord(s, &root);
    }

    dfs(text.size() - 1, text, &root);
    return 0;
}


#include <iostream>
#include <unordered_map>
#include <stack>
using namespace std;
/////////
stack<string> st;

struct Trie
{
    string word;
    Trie *edges[26];
    Trie()
    {
        word = "";
        for (int i = 0; i < 26; i++)
            edges[i] = NULL;
    }
} *root;

void addWord(string &w, Trie *t)
{
    char letter;
    for (int i = 0; i < w.size(); i++)
    {
        letter = tolower(w[i]);
        if (t->edges[letter - 'a'] == NULL)
            t->edges[letter - 'a'] = new Trie();
        t = t->edges[letter - 'a'];
    }

    if (t->word.empty())
        t->word = w;
}

void dfs(int index, string &s, Trie *t)
{
    if (index == -1)
    {
        if (t == root)
        {
            while (!st.empty())
            {
                cout << st.top() << ' ';
                st.pop();
            }
            exit(0);
        }
        return;
    }

    if (t->edges[s[index] - 'a'] == NULL)
        return;
    t = t->edges[s[index] - 'a'];

    if (!t->word.empty())
    {
        st.push(t->word);
        dfs(index - 1, s, root);
        st.pop();
    }

    dfs(index - 1, s, t);
}

int main()
{
    int n, m, i, j;
    cin >> n;
    string s, text, l, current;
    cin >> text >> m;
    root = new Trie();
    for (i = 0; i < m; i++)
    {
        cin >> s;
        addWord(s, root);
    }

    dfs(text.size() - 1, text, root);
    return 0;
}


#include <iostream>
#include <unordered_map>
#include <stack>
using namespace std;

unordered_map<string, string> h;
string w;
string text;
stack<string> result;

void dfs(int i)
{
    if (i == -1)
    {
        if (w == "")
        {
            while (!result.empty())
            {
                cout << h[result.top()] << ' ';
                result.pop();
            }
            exit(0);
        }
        return;
    }
    w += text[i];
    if (h[w] != "")
    {
        result.push(w);
        w = "";
        dfs(i - 1);
        /*stack<string> s2(result);
        while (!s2.empty())
            w += s2.top(), s2.pop();*/
        w = result.top();
        result.pop();
        dfs(i - 1);
    }
    else
        dfs(i - 1);
    w.pop_back();
}

int main()
{
    int n, m, i, j;
    cin >> n;
    string s, l;
    cin >> text >> m;
    for (i = 0; i < m; i++)
    {
        cin >> s;
        l = "";
        for (j = 0; j < s.size(); j++)
            l += tolower(s[j]);
        h[l] = s;
    }

    dfs(text.size() - 1);
    return 0;
}


#include <iostream>
#include <unordered_map>
#include <stack>
using namespace std;

unordered_map<string, string> h;
string w;
string text;
stack<string> result;

void dfs(int i)
{
    if (i == -1)
    {
        if (w == "")
        {
            while (!result.empty())
            {
                cout << h[result.top()] << ' ';
                result.pop();
            }
            exit(0);
        }
        return;
    }

    w += text[i];
    if (w == "osinghatesheandchildishiskira")
        cout << h[w];
    if (h[w] != "")
    {
        result.push(w);
        w = "";
        dfs(i - 1);
        w = text[i] + w;
        result.pop();
        dfs(i - 1);
    }
    else
        dfs(i - 1);
    w.pop_back();
}

int main()
{
    int n, m, i, j;
    cin >> n;
    string s, l;
    cin >> text >> m;
    for (i = 0; i < m; i++)
    {
        cin >> s;
        l = "";
        for (j = 0; j < s.size(); j++)
            l += tolower(s[j]);
        h[l] = s;
    }

    dfs(text.size() - 1);
    return 0;
}


#include <iostream>
#include <unordered_map>
#include <stack>
using namespace std;

stack<string> st;

struct Trie
{
    int words;
    string word;
    Trie *edges[26];
    Trie()
    {
        words = 0;
        for (int i = 0; i < 26; i++)
            edges[i] = NULL;
    }
} root;

void addWord(string &w, Trie *t)
{
    char letter;
    for (int i = 0; i < w.size(); i++)
    {
        letter = tolower(w[i]);
        if (t->edges[letter - 'a'] == NULL)
            t->edges[letter - 'a'] = new Trie();
        t = t->edges[letter - 'a'];
    }

    t->words++;
    t->word = w;
}

void dfs(int index, string &s, Trie *t)
{
    if (index == 0 && t->words)
    {
            cout << t->word << ' ';
            while (!st.empty())
            {
                cout << st.top() << ' ';
                st.pop();
            }
            exit(0);
    }

    if (t->words)
    {
        st.push(t->word);
        dfs(index, s, &root);
        st.pop();
    }

    if (t->edges[s[index] - 'a'] != NULL)
        dfs(index - 1, s, t->edges[s[index] - 'a']);
}

int main()
{
    int n, m, i, j;
    cin >> n;
    string s, text, l, current;
    cin >> text >> m;
    for (i = 0; i < m; i++)
    {
        cin >> s;
        addWord(s, &root);
    }

    dfs(text.size() - 2, text, root.edges[text.back() - 'a']);
    return 0;
}


#include <iostream>
#include <unordered_map>
#include <stack>
using namespace std;

unordered_map<string, string> h;
string w;
string text;
stack<string> result;

void dfs(int i)
{
    if (i == -1)
    {
        if (w == "")
        {
            while (!result.empty())
            {
                cout << h[result.top()] << ' ';
                result.pop();
            }
            exit(0);
        }
        return;
    }
    w += text[i];
    if (h.count(w))
    {
        result.push(w);
        w = "";
        dfs(i - 1);
        /*stack<string> s2(result);
        while (!s2.empty())
            w += s2.top(), s2.pop();*/
        w = result.top();
        result.pop();
        dfs(i - 1);
    }
    else
        dfs(i - 1);
    w.pop_back();
}

int main()
{
    ios_base::sync_with_stdio(false);
    int n, m, i, j;
    cin >> n;
    string s, l;
    cin >> text >> m;
    for (i = 0; i < m; i++)
    {
        cin >> s;
        l = "";
        for (j = 0; j < s.size(); j++)
            l += tolower(s[j]);
        h[l] = s;
    }

    dfs(text.size() - 1);
    return 0;
}


#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;
/////////
vector<string> sol;

struct Trie
{
    string word;
    Trie *edges[26];
    Trie()
    {
        word = "";
        for (int i = 0; i < 26; i++)
            edges[i] = NULL;
    }
} *root;

void addWord(string &w, Trie *t)
{
    char letter;
    for (int i = (int)w.size() - 1; i >= 0; i--)
    {
        letter = tolower(w[i]);
        if (t->edges[letter - 'a'] == NULL)
            t->edges[letter - 'a'] = new Trie();
        t = t->edges[letter - 'a'];
    }

    if (t->word.empty())
        t->word = w;
}

void dfs(int index, string &s, Trie *t)
{
    if (index == s.size())
    {
        if (t == root)
        {
            for (int i = 0; i < sol.size(); i++)
                cout << sol[i] << ' ';
            exit(0);
        }
        return;
    }

    if (t->edges[s[index] - 'a'] == NULL)
        return;
    t = t->edges[s[index] - 'a'];

    if (!t->word.empty())
    {
        sol.push_back(t->word);
        dfs(index + 1, s, root);
        sol.pop_back();
    }

    dfs(index + 1, s, t);
}

int main()
{
    ios_base::sync_with_stdio(false);
    int n, m, i;
    cin >> n;
    string s, text, l, current;
    cin >> text >> m;

    root = new Trie();
    for (i = 0; i < m; i++)
    {
        cin >> s;
        addWord(s, root);
    }

    dfs(0, text, root);
    return 0;
}


#include <iostream>
#include <unordered_map>
#include <stack>
using namespace std;
/////////
stack<string> st;

struct Trie
{
    string word;
    Trie *edges[26];
    Trie()
    {
        word = "";
        for (int i = 0; i < 26; i++)
            edges[i] = NULL;
    }
} *root;

void addWord(string &w, Trie *t)
{
    char letter;
    for (int i = 0; i < w.size(); i++)
    {
        letter = tolower(w[i]);
        if (t->edges[letter - 'a'] == NULL)
            t->edges[letter - 'a'] = new Trie();
        t = t->edges[letter - 'a'];
    }

    if (t->word.empty())
        t->word = w;
}

void dfs(int index, string &s, Trie *t)
{
    if (index == -1)
    {
        if (t == root)
        {
            while (!st.empty())
            {
                cout << st.top() << ' ';
                st.pop();
            }
            exit(0);
        }
        return;
    }

    if (t->edges[s[index] - 'a'] == NULL)
        return;
    t = t->edges[s[index] - 'a'];

    if (!t->word.empty())
    {
        st.push(t->word);
        dfs(index - 1, s, root);
        st.pop();
    }

    dfs(index - 1, s, t);
}

int main()
{
    int n, m, i, j;
    cin >> n;
    string s, text, l, current;
    cin >> text >> m;
    for (i = 0; i < text.size(); i++)
    {
        if ((i + 1) % 50 == 0)
            cout << '\n';
        cout << text[i];
    }

    root = new Trie();
    for (i = 0; i < m; i++)
    {
        cin >> s;
        addWord(s, root);
    }

    //dfs(text.size() - 1, text, root);
    return 0;
}


#include <iostream>
#include <unordered_map>
#include <stack>

using namespace std;
/////////
stack<string> st;

struct Trie
{
    string word;
    Trie *edges[26];
    Trie()
    {
        word = "";
        for (int i = 0; i < 26; i++)
            edges[i] = NULL;
    }
} *root;

void addWord(string &w, Trie *t)
{
    char letter;
    for (int i = 0; i < w.size(); i++)
    {
        letter = tolower(w[i]);
        if (t->edges[letter - 'a'] == NULL)
            t->edges[letter - 'a'] = new Trie();
        t = t->edges[letter - 'a'];
    }

    if (t->word.empty())
        t->word = w;
}

void dfs(int index, string &s, Trie *t)
{
    if (index == -1)
    {
        if (!t->word.empty())
        {
            cout << t->word << ' ';
            while (!st.empty())
                {
                    cout << st.top() << ' ';
                    st.pop();
                }
            exit(0);
        }
        return;
    }

    if (!t->word.empty())
    {
        st.push(t->word);
        dfs(index, s, root);
        st.pop();
    }

    if (t->edges[s[index] - 'a'] == NULL)
        return;
    t = t->edges[s[index] - 'a'];
    dfs(index - 1, s, t);
}

int main()
{
    int n, m, i, j;
    cin >> n;
    string s, text, l, current;
    cin >> text >> m;
    root = new Trie();
    for (i = 0; i < m; i++)
    {
        cin >> s;
        addWord(s, root);
    }

    dfs(text.size() - 1, text, root);
    return 0;
}


#include <iostream>
#include <unordered_map>
#include <stack>

using namespace std;
/////////
stack<string> st;

struct Trie
{
    string word;
    Trie *edges[26];
    Trie()
    {
        word = "";
        for (int i = 0; i < 26; i++)
            edges[i] = NULL;
    }
} *root;

void addWord(string &w, Trie *t)
{
    char letter;
    for (int i = 0; i < w.size(); i++)
    {
        letter = tolower(w[i]);
        if (t->edges[letter - 'a'] == NULL)
            t->edges[letter - 'a'] = new Trie();
        t = t->edges[letter - 'a'];
    }

    if (t->word.empty())
        t->word = w;
}

void dfs(int index, string &s, Trie *t)
{
    if (index == -1 && !t->word.empty())
    {
        cout << t->word << ' ';
        while (!st.empty())
            {
                cout << st.top() << ' ';
                st.pop();
            }
            exit(0);
    }

    if (!t->word.empty())
    {
        st.push(t->word);
        dfs(index, s, root);
        st.pop();
    }

    if (t->edges[s[index] - 'a'] == NULL)
        return;
    t = t->edges[s[index] - 'a'];
    dfs(index - 1, s, t);
}

int main()
{
    int n, m, i, j;
    cin >> n;
    string s, text, l, current;
    cin >> text >> m;
    root = new Trie();
    for (i = 0; i < m; i++)
    {
        cin >> s;
        addWord(s, root);
    }

    dfs(text.size() - 1, text, root);
    return 0;
}


#include <iostream>
#include <unordered_map>
#include <stack>
using namespace std;

unordered_map<string, string> h;
unordered_map<string, bool> h2;
string w;
string text;
stack<string> result;

void dfs(int i)
{
    if (i == -1)
    {
        if (w == "")
        {
            while (!result.empty())
            {
                cout << h[result.top()] << ' ';
                result.pop();
            }
            exit(0);
        }
        return;
    }
    w += text[i];
    if (h.count(w))
    {
        result.push(w);
        w = "";
        dfs(i - 1);
        /*stack<string> s2(result);
        while (!s2.empty())
            w += s2.top(), s2.pop();*/
        w = result.top();
        result.pop();
        dfs(i - 1);
    }
    else if (h2.count(w))
        dfs(i - 1);
    w.pop_back();
}

int main()
{
    ios_base::sync_with_stdio(false);
    int n, m, i, j;
    cin >> n;
    string s, l;
    cin >> text >> m;
    for (i = 0; i < m; i++)
    {
        cin >> s;
        l = "";
        for (j = 0; j < s.size(); j++)
        {
            l += tolower(s[j]);
            h2[l] = true;
        }
        h[l] = s;
    }

    dfs(text.size() - 1);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <stack>
#include <cstring>
#include <queue>
#include <algorithm>
#include <set>
#include <cmath>
#include <map>
#include <unordered_map>
//#define lson x<<1
//#define rson x<<1|1
//#define mid ((lt[x].l+lt[x].r)/2)
//#define ID(x, y) ((x)*m+(y))
//#define CHECK(x, y) ((x)>=0 && (x)<n && (y)>=0 && (y)<m)
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int INF=0x3f3f3f3f;
void Open()
{
    #ifndef ONLINE_JUDGE
        freopen("F:/in.txt","r",stdin);
        //freopen("F:/my.txt","w",stdout);
    #endif // ONLINE_JUDGE
}
const int N = 10010;
const int MAGIC = 31;
char str[N], sss[N];
unsigned int base[N];
unsigned int h[N];
unordered_map<unsigned int, int> m;
inline void init_hash(char *s, unsigned int *h, int l)
{
    h[0]= 0;
    for(int i = 1; i <= l;++i)
        h[i] = h[i-1] * MAGIC + s[i-1] - 'a';
    base[0] = 1;
    for(int i = 1; i <= l; ++i)
        base[i] = base[i-1] * MAGIC;
}
inline unsigned int string_hash(unsigned *h, int l, int r) //[0-base)
{
    return h[r] - h[l]* base[r-l];
}
struct word
{
    char ori[1111];
    char cur[1111];
    unsigned int hvalue;
    void update(int id)
    {
        strcpy(cur, ori);
        int len = strlen(cur);
        for(int i = 0; i < len; i++)
            if(cur[i] > 'z' || cur[i] < 'a')
                cur[i] -= 'A' - 'a';
        reverse(cur, cur+strlen(cur));
        //cout<<cur<<endl;
        len = strlen(cur);
        hvalue = 0;
        for(int i = 1; i <= len;i++)
            hvalue = hvalue * MAGIC + cur[i-1] - 'a';
        m[hvalue] = id;
    }
}s[N*10];
int pre[N], sta[N*10];
int main()
{
    //Open();
    memset(pre, -1, sizeof(pre));
    int len = 0;
    scanf("%d", &len);
    scanf("%s", str);
//    strcpy(sss, str);
//    reverse(sss, sss+len);
//    cout<<str<<endl;
//    cout<<sss<<endl;
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    {
        scanf("%s", s[i].ori);
        s[i].update(i);
    }
    init_hash(str, h, len);
    for(int i = 0; i < len; i++)
    {
        for(int j = i; j >= 0; j--)
        {
            if(m.find(string_hash(h, j, i+1)) != m.end() && (j == 0 || pre[j-1] != -1))
            {
                pre[i] = m[string_hash(h, j, i+1)];
                break;
            }
        }
    }
    int tail = 0;
    int idx = len-1;
    while(true)
    {
        if(idx < 0) break;
        sta[tail++] = pre[idx];
        if(idx + 1 == strlen(s[pre[idx]].cur)) break;
        else idx -= strlen(s[pre[idx]].cur);

    }
    for(int i = tail-1; i>= 0; i--)
        printf("%s%c", s[sta[i]].ori, " \n"[i == 0]);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <stack>
#include <cstring>
#include <queue>
#include <algorithm>
#include <set>
#include <cmath>
#include <map>
#include <unordered_map>
//#define lson x<<1
//#define rson x<<1|1
//#define mid ((lt[x].l+lt[x].r)/2)
//#define ID(x, y) ((x)*m+(y))
//#define CHECK(x, y) ((x)>=0 && (x)<n && (y)>=0 && (y)<m)
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int INF=0x3f3f3f3f;
void Open()
{
    #ifndef ONLINE_JUDGE
        freopen("F:/in.txt","r",stdin);
        //freopen("F:/my.txt","w",stdout);
    #endif // ONLINE_JUDGE
}
const int N = 10010;
const int MAGIC = 31;
char str[N], sss[N];
unsigned int base[N];
unsigned int h[N];
unordered_map<unsigned int, int> m;
inline void init_hash(char *s, unsigned int *h, int l)
{
    h[0]= 0;
    for(int i = 1; i <= l;++i)
        h[i] = h[i-1] * MAGIC + s[i-1] - 'a';
    base[0] = 1;
    for(int i = 1; i <= l; ++i)
        base[i] = base[i-1] * MAGIC;
}
inline unsigned int string_hash(unsigned *h, int l, int r) //[0-base)
{
    return h[r] - h[l]* base[r-l];
}
struct word
{
    char ori[1111];
    char cur[1111];
    unsigned int hvalue;
    void update(int id)
    {
        strcpy(cur, ori);
        int len = strlen(cur);
        for(int i = 0; i < len; i++)
            if(cur[i] > 'z' || cur[i] < 'a')
                cur[i] -= 'A' - 'a';
        reverse(cur, cur+strlen(cur));
        //cout<<cur<<endl;
        len = strlen(cur);
        hvalue = 0;
        for(int i = 1; i <= len;i++)
            hvalue = hvalue * MAGIC + cur[i-1] - 'a';
        m[hvalue] = id;
    }
}s[N*10];
int pre[N], sta[N*10];
int main()
{
    //Open();
    memset(pre, -1, sizeof(pre));
    int len = 0;
    scanf("%d", &len);
    scanf("%s", str);
//    strcpy(sss, str);
//    reverse(sss, sss+len);
//    cout<<str<<endl;
//    cout<<sss<<endl;
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    {
        scanf("%s", s[i].ori);
        s[i].update(i);
    }
    init_hash(str, h, len);
    for(int i = 0; i < len; i++)
    {
        for(int j = i; j >= 0; j--)
        {
            if(m.find(string_hash(h, j, i+1)) != m.end() && (j == 0 || pre[j-1] != -1))
                pre[i] = m[string_hash(h, j, i+1)];
        }
    }
    int tail = 0;
    int idx = len-1;
    while(idx >= 0)
    {
        sta[tail++] = pre[idx];
        if(idx + 1 == strlen(s[pre[idx]].cur)) break;
        else idx -= strlen(s[pre[idx]].cur);

    }
    for(int i = tail-1; i>= 0; i--)
        printf("%s%c", s[sta[i]].ori, " \n"[i == 0]);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <stack>
#include <cstring>
#include <queue>
#include <algorithm>
#include <set>
#include <cmath>
#include <map>
#include <unordered_map>
//#define lson x<<1
//#define rson x<<1|1
//#define mid ((lt[x].l+lt[x].r)/2)
//#define ID(x, y) ((x)*m+(y))
//#define CHECK(x, y) ((x)>=0 && (x)<n && (y)>=0 && (y)<m)
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
typedef unsigned long long ULL;
const LL INF=0x3f3f3f3f;
void Open()
{
    #ifndef ONLINE_JUDGE
        freopen("F:/in.txt","r",stdin);
        //freopen("F:/my.txt","w",stdout);
    #endif // ONLINE_JUDGE
}
const LL N = 10010;
const LL MAGIC = 37;
char str[N], sss[N];
ULL base[N];
ULL h[N];
unordered_map<ULL, LL> m;
inline void init_hash(char *s, ULL *h, LL l)
{
    h[0]= 0;
    for(LL i = 1; i <= l;++i)
        h[i] = h[i-1] * MAGIC + s[i-1] - 'a';
    base[0] = 1;
    for(LL i = 1; i <= l; ++i)
        base[i] = base[i-1] * MAGIC;
}
inline ULL string_hash(ULL *h, LL l, LL r) //[0-base)
{
    return h[r] - h[l]* base[r-l];
}
struct word
{
    char ori[1111];
    char cur[1111];
    ULL hvalue;
    void update(LL id)
    {
        strcpy(cur, ori);
        LL len = strlen(cur);
        for(LL i = 0; i < len; i++)
            if(cur[i] > 'z' || cur[i] < 'a')
                cur[i] -= 'A' - 'a';
        reverse(cur, cur+len);
        hvalue = 0;
        for(LL i = 1; i <= len;i++)
            hvalue = hvalue * MAGIC + cur[i-1] - 'a';
        m[hvalue] = id;
    }
}s[N*10];
LL pre[N], sta[N*10];
int main()
{
    //Open();
    memset(pre, -1, sizeof(pre));
    LL len = 0;
    scanf("%I64d", &len);
    scanf("%s", str);
//    strcpy(sss, str);
//    reverse(sss, sss+len);
//    cout<<str<<endl;
//    cout<<sss<<endl;
    LL n;
    scanf("%I64d", &n);
    for(LL i = 0; i < n; i++)
    {
        scanf("%s", s[i].ori);
        s[i].update(i);
    }
    init_hash(str, h, len);
    for(LL i = 0; i < len; i++)
    {
        for(LL j = 0; j <= i; j++)
        {
            if(m.find(string_hash(h, j, i+1)) != m.end() && (j == 0 || pre[j-1] != -1))
            {
                pre[i] = m[string_hash(h, j, i+1)];
                break;
            }
        }
    }
    LL tail = 0;
    LL idx = len-1;
    while(true)
    {
        if(idx < 0) break;
        sta[tail++] = pre[idx];
        if(idx + 1 == strlen(s[pre[idx]].cur)) break;
        else idx -= strlen(s[pre[idx]].cur);

    }
    for(LL i = tail-1; i>= 0; i--)
        printf("%s%c", s[sta[i]].ori, " \n"[i == 0]);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <stack>
#include <cstring>
#include <queue>
#include <algorithm>
#include <set>
#include <cmath>
#include <map>
#include <unordered_map>
//#define lson x<<1
//#define rson x<<1|1
//#define mid ((lt[x].l+lt[x].r)/2)
//#define ID(x, y) ((x)*m+(y))
//#define CHECK(x, y) ((x)>=0 && (x)<n && (y)>=0 && (y)<m)
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
typedef unsigned long long ULL;
typedef pair<ULL, ULL> PUU;
const LL INF=0x3f3f3f3f;
void Open()
{
    #ifndef ONLINE_JUDGE
        freopen("F:/in.txt","r",stdin);
        //freopen("F:/my.txt","w",stdout);
    #endif // ONLINE_JUDGE
}
const LL N = 10010;
//const LL MAGIC = 998244353;
char str[N], sss[N];
ULL base[N], rbase[N];
ULL h[N];
ULL rh[N];
map<PUU, string> m;
map<PUU, string> m1;

inline void init_hash(char *s, ULL *h, ULL *base, LL l, LL MAGIC)
{
    h[0]= 0;
    for(LL i = 1; i <= l;++i)
        h[i] = h[i-1] * MAGIC + s[i-1] - 'a';
    base[0] = 1;
    for(LL i = 1; i <= l; ++i)
        base[i] = base[i-1] * MAGIC;
}
inline ULL string_hash(ULL *h, ULL *base, LL l, LL r) //[0-base)
{
    return h[r] - h[l] * base[r-l];
}
struct word
{
    char ori[1111];
    char cur[1111];
    ULL hvalue;
    void update(LL id)
    {
        strcpy(cur, ori);
        LL len = strlen(cur);
        for(LL i = 0; i < len; i++)
            if(cur[i] > 'z' || cur[i] < 'a')
                cur[i] -= 'A' - 'a';
        reverse(cur, cur+len);
        hvalue = 0;
        for(LL i = 1; i <= len;i++)
            hvalue = hvalue * 31LL + cur[i-1] - 'a';
        ULL rvalue = 0;
        for(LL i = 1; i <= len;i++)
            rvalue = rvalue * 171LL + cur[i-1] - 'a';
        if(m.find(PUU(hvalue, rvalue)) != m.end() && string(cur).compare(m[PUU(hvalue, rvalue)])) hvalue /= 0;
        m[PUU(hvalue, rvalue)] = string(cur);
        m1[PUU(hvalue, rvalue)] = string(ori);
    }
}s[N*10];
string pre[N];
string sta[N*10];
int main()
{
    //Open();
    //memset(pre, 0, sizeof(pre));
    LL len = 0;
    scanf("%I64d", &len);
    scanf("%s", str);
    LL n;
    scanf("%I64d", &n);
    LL ma = 0;
    for(LL i = 0; i < n; i++)
    {
        scanf("%s", s[i].ori);
        s[i].update(i);
        ma = max(ma, (LL)strlen(s[i].ori));
    }
    init_hash(str, h, base, len, 31);
    //reverse(str, str+len);
    init_hash(str, rh, rbase, len, 171);
    //reverse(str, str+len);
    for(LL i = 0; i < len; i++)
    {
        for(LL j = max(0LL, i - ma - 1); j <= i; j++)
        {
            if(m1.find(PUU(string_hash(h, base, j, i+1), string_hash(rh, rbase, j, i+1))) != m1.end() && (j == 0 || !pre[j-1].empty()))
            {
                //cout<<m[string_hash(h, j, i+1)]<<endl;
                pre[i] = m1[PUU(string_hash(h, base, j, i+1), string_hash(rh, rbase, j, i+1))];
                break;
            }
        }
    }
    LL tail = 0;
    LL idx = len-1;
    while(true)
    {
        if(idx < 0) break;
        sta[tail++] = pre[idx];
        if(idx + 1 == pre[idx].length()) break;
        else idx -= pre[idx].length();

    }
    for(LL i = tail-1; i>= 0; i--)
        printf("%s%c", sta[i].c_str(), " \n"[i == 0]);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <stack>
#include <cstring>
#include <queue>
#include <algorithm>
#include <set>
#include <cmath>
#include <map>
#include <unordered_map>
//#define lson x<<1
//#define rson x<<1|1
//#define mid ((lt[x].l+lt[x].r)/2)
//#define ID(x, y) ((x)*m+(y))
//#define CHECK(x, y) ((x)>=0 && (x)<n && (y)>=0 && (y)<m)
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int INF=0x3f3f3f3f;
void Open()
{
    #ifndef ONLINE_JUDGE
        freopen("F:/in.txt","r",stdin);
        //freopen("F:/my.txt","w",stdout);
    #endif // ONLINE_JUDGE
}
const int N = 10010;
const int MAGIC = 131;
char str[N];
unordered_map<unsigned int, int> m;
struct word
{
    char ori[1111];
    char cur[1111];
    unsigned int hvalue;
    void update(int id)
    {
        strcpy(cur, ori);
        int len = strlen(cur);
        for(int i = 0; i < len; i++)
            if(cur[i] > 'z' || cur[i] < 'a')
                cur[i] -= 'A' - 'a';
        //reverse(cur, cur+strlen(cur));
        //cout<<cur<<endl;
        len = strlen(cur);
        hvalue = 0;
        for(int i = 1; i <= len;i++)
            hvalue = hvalue * MAGIC + cur[i-1] - 'a';
        m[hvalue] = id;
    }
}s[N*10];
int pre[N], sta[N*10];
int main()
{
    //Open();
    memset(pre, -1, sizeof(pre));
    int len = 0;
    scanf("%d", &len);
    scanf("%s", str);
//    strcpy(sss, str);
//    reverse(sss, sss+len);
//    cout<<str<<endl;
//    cout<<sss<<endl;
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    {
        scanf("%s", s[i].ori);
        s[i].update(i);
    }
    //init_hash(str, h, len);
    for(int i = 0; i < len; i++)
    {
        int ch = 0;
        for(int j = i; j >= max(0, i-1001); j--)
        {
            ch = ch * MAGIC + str[j] - 'a';
            if(m.find(ch) != m.end() && (j == 0 || pre[j-1] != -1))
                pre[i] = m[ch];
        }
    }
    int tail = 0;
    int idx = len-1;
    while(idx >= 0)
    {
        sta[tail++] = pre[idx];
        //if(idx + 1 == strlen(s[pre[idx]].cur)) break;
        idx -= strlen(s[pre[idx]].cur);

    }
    for(int i = tail-1; i>= 0; i--)
        printf("%s%c", s[sta[i]].ori, " \n"[i == 0]);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <stack>
#include <cstring>
#include <queue>
#include <algorithm>
#include <set>
#include <cmath>
#include <map>
#include <unordered_map>
//#define lson x<<1
//#define rson x<<1|1
//#define mid ((lt[x].l+lt[x].r)/2)
//#define ID(x, y) ((x)*m+(y))
//#define CHECK(x, y) ((x)>=0 && (x)<n && (y)>=0 && (y)<m)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
const int INF=0x3f3f3f3f;
void Open()
{
    #ifndef ONLINE_JUDGE
        freopen("F:/in.txt","r",stdin);
        //freopen("F:/my.txt","w",stdout);
    #endif // ONLINE_JUDGE
}
const int N = 10010;
const int MAGIC = 131;
char str[N];
unordered_map<ULL, int> m;
struct word
{
    char ori[1111];
    char cur[1111];
    ULL hvalue;
    void update(int id)
    {
        strcpy(cur, ori);
        int len = strlen(cur);
        for(int i = 0; i < len; i++)
            cur[i] = tolower(cur[i]);
        //reverse(cur, cur+strlen(cur));
        //cout<<cur<<endl;
        len = strlen(cur);
        hvalue = 0;
        for(int i = 1; i <= len;i++)
            hvalue = hvalue * MAGIC + cur[i-1];
        m[hvalue] = id;
    }
}s[N*10];
int pre[N], sta[N*10];
int main()
{
    //Open();
    memset(pre, -1, sizeof(pre));
    int len = 0;
    scanf("%d", &len);
    scanf("%s", str);
//    strcpy(sss, str);
//    reverse(sss, sss+len);
//    cout<<str<<endl;
//    cout<<sss<<endl;
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    {
        scanf("%s", s[i].ori);
        s[i].update(i);
    }
    //init_hash(str, h, len);
    for(int i = 0; i < len; i++)
    {
        ULL ch = 0;
        for(int j = i; j >= max(0, i-1001); j--)
        {
            ch = ch * MAGIC + str[j];
            if(m.find(ch) != m.end() && (j == 0 || pre[j-1] != -1))
                pre[i] = m[ch];
        }
    }
    int tail = 0;
    int idx = len-1;
    while(idx >= 0)
    {
        sta[tail++] = pre[idx];
        //if(idx + 1 == strlen(s[pre[idx]].cur)) break;
        idx -= strlen(s[pre[idx]].ori);

    }
    for(int i = tail-1; i>= 0; i--)
        printf("%s%c", s[sta[i]].ori, " \n"[i == 0]);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <stack>
#include <cstring>
#include <queue>
#include <algorithm>
#include <set>
#include <cmath>
#include <map>
#include <unordered_map>
//#define lson x<<1
//#define rson x<<1|1
//#define mid ((lt[x].l+lt[x].r)/2)
//#define ID(x, y) ((x)*m+(y))
//#define CHECK(x, y) ((x)>=0 && (x)<n && (y)>=0 && (y)<m)
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
typedef unsigned long long ULL;
typedef pair<ULL, ULL> PUU;
const LL INF=0x3f3f3f3f;
void Open()
{
    #ifndef ONLINE_JUDGE
        freopen("F:/in.txt","r",stdin);
        //freopen("F:/my.txt","w",stdout);
    #endif // ONLINE_JUDGE
}
const LL N = 10010;
const LL MAGIC = 179;
char str[N], sss[N];
ULL base[N];
ULL h[N];
ULL rh[N];
map<PUU, string> m;
map<PUU, string> m1;

inline void init_hash(char *s, ULL *h, LL l)
{
    h[0]= 0;
    for(LL i = 1; i <= l;++i)
        h[i] = h[i-1] * MAGIC + s[i-1] - 'a';
    base[0] = 1;
    for(LL i = 1; i <= l; ++i)
        base[i] = base[i-1] * MAGIC;
}
inline ULL string_hash(ULL *h, LL l, LL r) //[0-base)
{
    return h[r] - h[l] * base[r-l];
}
struct word
{
    char ori[1111];
    char cur[1111];
    ULL hvalue;
    void update(LL id)
    {
        strcpy(cur, ori);
        LL len = strlen(cur);
        for(LL i = 0; i < len; i++)
            if(cur[i] > 'z' || cur[i] < 'a')
                cur[i] -= 'A' - 'a';
        reverse(cur, cur+len);
        hvalue = 0;
        for(LL i = 1; i <= len;i++)
            hvalue = hvalue * MAGIC + cur[i-1] - 'a';
        ULL rvalue = 0;
        for(int i = len; i >= 1; i--)
            rvalue = rvalue * MAGIC + cur[i-1] - 'a';
        //if(m.find(PUU(hvalue, rvalue)) != m.end() && string(cur).compare(m[PUU(hvalue, rvalue)])) hvalue /= 0;
        m[PUU(hvalue, rvalue)] = string(cur);
        m1[PUU(hvalue, rvalue)] = string(ori);
    }
}s[N*10];
string pre[N];
string sta[N*10];
int main()
{
    //Open();
    //memset(pre, 0, sizeof(pre));
    LL len = 0;
    scanf("%I64d", &len);
    scanf("%s", str);
    LL n;
    scanf("%I64d", &n);
    LL ma = 0;
    for(LL i = 0; i < n; i++)
    {
        scanf("%s", s[i].ori);
        s[i].update(i);
        ma = max(ma, (LL)strlen(s[i].ori));
    }
    init_hash(str, h, len);
    reverse(str, str+len);
    init_hash(str, rh, len);
    reverse(str, str+len);
    for(LL i = 0; i < len; i++)
    {
        for(LL j = max(0LL, i - ma - 1); j <= i; j++)
        {
            if(m1.find(PUU(string_hash(h, j, i+1), string_hash(rh, len-i-1, len-j))) != m1.end() && (j == 0 || !pre[j-1].empty()))
            {
                //cout<<m[string_hash(h, j, i+1)]<<endl;
                pre[i] = m1[PUU(string_hash(h, j, i+1), string_hash(rh, len-i-1, len-j))];
                break;
            }
        }
    }
    LL tail = 0;
    LL idx = len-1;
    while(true)
    {
        if(idx < 0) break;
        sta[tail++] = pre[idx];
        if(idx + 1 == pre[idx].length()) break;
        else idx -= pre[idx].length();

    }
    for(LL i = tail-1; i>= 0; i--)
        printf("%s%c", sta[i].c_str(), " \n"[i == 0]);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <stack>
#include <cstring>
#include <queue>
#include <algorithm>
#include <set>
#include <cmath>
#include <map>
#include <unordered_map>
//#define lson x<<1
//#define rson x<<1|1
//#define mid ((lt[x].l+lt[x].r)/2)
//#define ID(x, y) ((x)*m+(y))
//#define CHECK(x, y) ((x)>=0 && (x)<n && (y)>=0 && (y)<m)
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
typedef unsigned long long ULL;
const LL INF=0x3f3f3f3f;
void Open()
{
    #ifndef ONLINE_JUDGE
        freopen("F:/in.txt","r",stdin);
        //freopen("F:/my.txt","w",stdout);
    #endif // ONLINE_JUDGE
}
const LL N = 10010;
const LL MAGIC = 37;
char str[N], sss[N];
ULL base[N];
ULL h[N];
unordered_map<ULL, string> m;
unordered_map<ULL, string> m1;

inline void init_hash(char *s, ULL *h, LL l)
{
    h[0]= 0;
    for(LL i = 1; i <= l;++i)
        h[i] = h[i-1] * MAGIC + s[i-1] - 'a';
    base[0] = 1;
    for(LL i = 1; i <= l; ++i)
        base[i] = base[i-1] * MAGIC;
}
inline ULL string_hash(ULL *h, LL l, LL r) //[0-base)
{
    return h[r] - h[l] * base[r-l];
}
struct word
{
    char ori[1111];
    char cur[1111];
    ULL hvalue;
    void update(LL id)
    {
        strcpy(cur, ori);
        LL len = strlen(cur);
        for(LL i = 0; i < len; i++)
            if(cur[i] > 'z' || cur[i] < 'a')
                cur[i] -= 'A' - 'a';
        reverse(cur, cur+len);
        hvalue = 0;
        for(LL i = 1; i <= len;i++)
            hvalue = hvalue * MAGIC + cur[i-1] - 'a';
        if(m.find(hvalue) != m.end() && string(cur).compare(m[hvalue])) hvalue /= 0;
        m[hvalue] = string(cur);
        m1[hvalue] = string(ori);
    }
}s[N*10];
string pre[N];
string sta[N*10];
int main()
{
    //Open();
    //memset(pre, 0, sizeof(pre));
    LL len = 0;
    scanf("%I64d", &len);
    scanf("%s", str);
    LL n;
    scanf("%I64d", &n);
    for(LL i = 0; i < n; i++)
    {
        scanf("%s", s[i].ori);
        s[i].update(i);
    }
    init_hash(str, h, len);
    for(LL i = 0; i < len; i++)
    {
        for(LL j = 0; j <= i; j++)
        {
            if(m1.find(string_hash(h, j, i+1)) != m.end() && (j == 0 || !pre[j-1].empty()))
            {
                //cout<<m[string_hash(h, j, i+1)]<<endl;
                pre[i] = m1[string_hash(h, j, i+1)];
                break;
            }
        }
    }
    LL tail = 0;
    LL idx = len-1;
    while(true)
    {
        if(idx < 0) break;
        sta[tail++] = pre[idx];
        if(idx + 1 == pre[idx].length()) break;
        else idx -= pre[idx].length();

    }
    for(LL i = tail-1; i>= 0; i--)
        printf("%s%c", sta[i].c_str(), " \n"[i == 0]);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <stack>
#include <cstring>
#include <queue>
#include <algorithm>
#include <set>
#include <cmath>
#include <map>
#include <unordered_map>
//#define lson x<<1
//#define rson x<<1|1
//#define mid ((lt[x].l+lt[x].r)/2)
//#define ID(x, y) ((x)*m+(y))
//#define CHECK(x, y) ((x)>=0 && (x)<n && (y)>=0 && (y)<m)
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
typedef unsigned long long ULL;
const LL INF=0x3f3f3f3f;
void Open()
{
    #ifndef ONLINE_JUDGE
        freopen("F:/in.txt","r",stdin);
        //freopen("F:/my.txt","w",stdout);
    #endif // ONLINE_JUDGE
}
const LL N = 10010;
const LL MAGIC = 37;
char str[N], sss[N];
ULL base[N];
ULL h[N];
unordered_map<ULL, string> m;
unordered_map<ULL, string> m1;

inline void init_hash(char *s, ULL *h, LL l)
{
    h[0]= 0;
    for(LL i = 1; i <= l;++i)
        h[i] = h[i-1] * MAGIC + s[i-1] - 'a';
    base[0] = 1;
    for(LL i = 1; i <= l; ++i)
        base[i] = base[i-1] * MAGIC;
}
inline ULL string_hash(ULL *h, LL l, LL r) //[0-base)
{
    return h[r] - h[l] * base[r-l];
}
struct word
{
    char ori[1111];
    char cur[1111];
    ULL hvalue;
    void update(LL id)
    {
        strcpy(cur, ori);
        LL len = strlen(cur);
        for(LL i = 0; i < len; i++)
            if(cur[i] > 'z' || cur[i] < 'a')
                cur[i] -= 'A' - 'a';
        reverse(cur, cur+len);
        hvalue = 0;
        for(LL i = 1; i <= len;i++)
            hvalue = hvalue * MAGIC + cur[i-1] - 'a';
        //if(m.find(hvalue) != m.end() && string(cur).compare(m[hvalue])) hvalue /= 0;
        m[hvalue] = string(cur);
        m1[hvalue] = string(ori);
    }
}s[N*10];
string pre[N];
string sta[N*10];
int main()
{
    //Open();
    //memset(pre, 0, sizeof(pre));
    LL len = 0;
    scanf("%I64d", &len);
    scanf("%s", str);
    LL n;
    scanf("%I64d", &n);
    for(LL i = 0; i < n; i++)
    {
        scanf("%s", s[i].ori);
        s[i].update(i);
    }
    init_hash(str, h, len);
    for(LL i = 0; i < len; i++)
    {
        for(LL j = 0; j <= i; j++)
        {
            if(m1.find(string_hash(h, j, i+1)) != m.end() && (j == 0 || !pre[j-1].empty()))
            {
                //cout<<m[string_hash(h, j, i+1)]<<endl;
                pre[i] = m1[string_hash(h, j, i+1)];
                break;
            }
        }
    }
    LL tail = 0;
    LL idx = len-1;
    while(true)
    {
        if(idx < 0) break;
        sta[tail++] = pre[idx];
        if(idx + 1 == pre[idx].length()) break;
        else idx -= pre[idx].length();

    }
    for(LL i = tail-1; i>= 0; i--)
        printf("%s%c", sta[i].c_str(), " \n"[i == 0]);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <stack>
#include <cstring>
#include <queue>
#include <algorithm>
#include <set>
#include <cmath>
#include <map>
#include <unordered_map>
//#define lson x<<1
//#define rson x<<1|1
//#define mid ((lt[x].l+lt[x].r)/2)
//#define ID(x, y) ((x)*m+(y))
//#define CHECK(x, y) ((x)>=0 && (x)<n && (y)>=0 && (y)<m)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
const int INF=0x3f3f3f3f;
void Open()
{
    #ifndef ONLINE_JUDGE
        freopen("F:/in.txt","r",stdin);
        //freopen("F:/my.txt","w",stdout);
    #endif // ONLINE_JUDGE
}
const int N = 10010;
const int MAGIC = 123;
char str[N];
unordered_map<ULL, int> m;
struct word
{
    char ori[1111];
    char cur[1111];
    ULL hvalue;
    void update(int id)
    {
        strcpy(cur, ori);
        int len = strlen(cur);
        for(int i = 0; i < len; i++)
            cur[i] = tolower(cur[i]);
        //reverse(cur, cur+strlen(cur));
        //cout<<cur<<endl;
        len = strlen(cur);
        hvalue = 0;
        for(int i = 1; i <= len;i++)
            hvalue = hvalue * MAGIC + cur[i-1];
        m[hvalue] = id;
    }
}s[N*10];
int pre[N], sta[N*10];
int main()
{
    //Open();
    memset(pre, -1, sizeof(pre));
    int len = 0;
    scanf("%d", &len);
    scanf("%s", str);
//    strcpy(sss, str);
//    reverse(sss, sss+len);
//    cout<<str<<endl;
//    cout<<sss<<endl;
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    {
        scanf("%s", s[i].ori);
        s[i].update(i);
    }
    //init_hash(str, h, len);
    for(int i = 0; i < len; i++)
    {
        ULL ch = 0;
        for(int j = i; j >= max(0, i-1001); j--)
        {
            ch = ch * MAGIC + str[j];
            if(m.find(ch) != m.end() && (j == 0 || pre[j-1] != -1))
                pre[i] = m[ch];
        }
    }
    int tail = 0;
    int idx = len-1;
    while(idx >= 0)
    {
        sta[tail++] = pre[idx];
        //if(idx + 1 == strlen(s[pre[idx]].cur)) break;
        idx -= strlen(s[pre[idx]].ori);

    }
    for(int i = tail-1; i>= 0; i--)
        printf("%s%c", s[sta[i]].ori, " \n"[i == 0]);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <stack>
#include <cstring>
#include <queue>
#include <algorithm>
#include <set>
#include <cmath>
#include <map>
#include <unordered_map>
//#define lson x<<1
//#define rson x<<1|1
//#define mid ((lt[x].l+lt[x].r)/2)
//#define ID(x, y) ((x)*m+(y))
//#define CHECK(x, y) ((x)>=0 && (x)<n && (y)>=0 && (y)<m)
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int INF=0x3f3f3f3f;
void Open()
{
    #ifndef ONLINE_JUDGE
        freopen("F:/in.txt","r",stdin);
        //freopen("F:/my.txt","w",stdout);
    #endif // ONLINE_JUDGE
}
const int N = 10010;
const int MAGIC = 31;
char str[N], sss[N];
unsigned int base[N];
unsigned int h[N];
unordered_map<unsigned int, int> m;
inline void init_hash(char *s, unsigned int *h, int l)
{
    h[0]= 0;
    for(int i = 1; i <= l;++i)
        h[i] = h[i-1] * MAGIC + s[i-1] - 'a';
    base[0] = 1;
    for(int i = 1; i <= l; ++i)
        base[i] = base[i-1] * MAGIC;
}
inline unsigned int string_hash(unsigned *h, int l, int r) //[0-base)
{
    return h[r] - h[l]* base[r-l];
}
struct word
{
    char ori[1111];
    char cur[1111];
    unsigned int hvalue;
    void update(int id)
    {
        strcpy(cur, ori);
        int len = strlen(cur);
        for(int i = 0; i < len; i++)
            if(cur[i] > 'z' || cur[i] < 'a')
                cur[i] -= 'A' - 'a';
        reverse(cur, cur+strlen(cur));
        //cout<<cur<<endl;
        len = strlen(cur);
        hvalue = 0;
        for(int i = 1; i <= len;i++)
            hvalue = hvalue * MAGIC + cur[i-1] - 'a';
        m[hvalue] = id;
    }
}s[N*10];
int pre[N], sta[N*10];
int main()
{
    //Open();
    memset(pre, -1, sizeof(pre));
    int len = 0;
    scanf("%d", &len);
    scanf("%s", str);
//    strcpy(sss, str);
//    reverse(sss, sss+len);
//    cout<<str<<endl;
//    cout<<sss<<endl;
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    {
        scanf("%s", s[i].ori);
        s[i].update(i);
    }
    init_hash(str, h, len);
    for(int i = 0; i < len; i++)
    {
        for(int j = i; j >= 0; j--)
        {
            if(m.find(string_hash(h, j, i+1)) != m.end() && (j == 0 || pre[j-1] != -1))
            {
                pre[i] = m[string_hash(h, j, i+1)];
                break;
            }
        }
    }
    int tail = 0;
    int idx = len-1;
    while(true)
    {
        if(idx < 0) idx /= 0;
        sta[tail++] = pre[idx];
        if(idx + 1 == strlen(s[pre[idx]].cur)) break;
        else idx -= strlen(s[pre[idx]].cur);

    }
    for(int i = tail-1; i>= 0; i--)
        printf("%s%c", s[sta[i]].ori, " \n"[i == 0]);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <stack>
#include <cstring>
#include <queue>
#include <algorithm>
#include <set>
#include <cmath>
#include <map>
#include <unordered_map>
//#define lson x<<1
//#define rson x<<1|1
//#define mid ((lt[x].l+lt[x].r)/2)
//#define ID(x, y) ((x)*m+(y))
//#define CHECK(x, y) ((x)>=0 && (x)<n && (y)>=0 && (y)<m)
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int INF=0x3f3f3f3f;
void Open()
{
    #ifndef ONLINE_JUDGE
        freopen("F:/in.txt","r",stdin);
        //freopen("F:/my.txt","w",stdout);
    #endif // ONLINE_JUDGE
}
const int N = 10010;
const int MAGIC = 123;
char str[N];
unordered_map<unsigned int, int> m;
struct word
{
    char ori[1111];
    char cur[1111];
    unsigned int hvalue;
    void update(int id)
    {
        strcpy(cur, ori);
        int len = strlen(cur);
        for(int i = 0; i < len; i++)
            cur[i] = tolower(cur[i]);
        //reverse(cur, cur+strlen(cur));
        //cout<<cur<<endl;
        len = strlen(cur);
        hvalue = 0;
        for(int i = 1; i <= len;i++)
            hvalue = hvalue * MAGIC + cur[i-1];
        m[hvalue] = id;
    }
}s[N*10];
int pre[N], sta[N*10];
int main()
{
    //Open();
    memset(pre, -1, sizeof(pre));
    int len = 0;
    scanf("%d", &len);
    scanf("%s", str);
//    strcpy(sss, str);
//    reverse(sss, sss+len);
//    cout<<str<<endl;
//    cout<<sss<<endl;
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    {
        scanf("%s", s[i].ori);
        s[i].update(i);
    }
    //init_hash(str, h, len);
    for(int i = 0; i < len; i++)
    {
        int ch = 0;
        for(int j = i; j >= max(0, i-1001); j--)
        {
            ch = ch * MAGIC + str[j];
            if(m.find(ch) != m.end() && (j == 0 || pre[j-1] != -1))
                pre[i] = m[ch];
        }
    }
    int tail = 0;
    int idx = len-1;
    while(idx >= 0)
    {
        sta[tail++] = pre[idx];
        //if(idx + 1 == strlen(s[pre[idx]].cur)) break;
        idx -= strlen(s[pre[idx]].ori);

    }
    for(int i = tail-1; i>= 0; i--)
        printf("%s%c", s[sta[i]].ori, " \n"[i == 0]);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <stack>
#include <cstring>
#include <queue>
#include <algorithm>
#include <set>
#include <cmath>
#include <map>
#include <unordered_map>
//#define lson x<<1
//#define rson x<<1|1
//#define mid ((lt[x].l+lt[x].r)/2)
//#define ID(x, y) ((x)*m+(y))
//#define CHECK(x, y) ((x)>=0 && (x)<n && (y)>=0 && (y)<m)
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int INF=0x3f3f3f3f;
void Open()
{
    #ifndef ONLINE_JUDGE
        freopen("F:/in.txt","r",stdin);
        //freopen("F:/my.txt","w",stdout);
    #endif // ONLINE_JUDGE
}
const int N = 100010;
const int MAGIC = 31;
char str[N], sss[N];
unsigned int base[N];
unsigned int h[N];
unordered_map<unsigned, int> m;
inline void init_hash(char *s, unsigned int *h, int l)
{
    h[0]= 0;
    for(int i = 1; i <= l;++i)
        h[i] = h[i-1] * MAGIC + s[i-1] - 'a';
    base[0] = 1;
    for(int i = 1; i <= l; ++i)
        base[i] = base[i-1] * MAGIC;
}
inline unsigned int string_hash(unsigned *h, int l, int r) //[0-base)
{
    return h[r] - h[l]* base[r-l];
}
struct word
{
    char ori[1111];
    char cur[1111];
    unsigned int hvalue;
    void update(int id)
    {
        strcpy(cur, ori);
        int len = strlen(cur);
        for(int i = 0; i < len; i++)
            if(cur[i] > 'z' || cur[i] < 'a')
                cur[i] -= 'A' - 'a';
        reverse(cur, cur+strlen(cur));
        //cout<<cur<<endl;
        len = strlen(cur);
        hvalue = 0;
        for(int i = 1; i <= len;i++)
            hvalue = hvalue * MAGIC + cur[i-1] - 'a';
        m[hvalue] = id;
    }
}s[N];
int pre[N], sta[N];
int main()
{
    //Open();
    memset(pre, -1, sizeof(pre));
    int len = 0;
    scanf("%d", &len);
    scanf("%s", str);
//    strcpy(sss, str);
//    reverse(sss, sss+len);
//    cout<<str<<endl;
//    cout<<sss<<endl;
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    {
        scanf("%s", s[i].ori);
        s[i].update(i);
    }
    init_hash(str, h, len);
    for(int i = 0; i < len; i++)
    {
        for(int j = i; j >= 0; j--)
        {
            if(m.find(string_hash(h, j, i+1)) != m.end() && (j == 0 || pre[j-1] != -1))
                pre[i] = m[string_hash(h, j, i+1)];
        }
    }
    int tail = 0;
    int idx = len-1;
    while(true)
    {
        sta[tail++] = pre[idx];
        if(idx + 1 == strlen(s[pre[idx]].cur)) break;
        else idx -= strlen(s[pre[idx]].cur);

    }
    for(int i = tail-1; i>= 0; i--)
        printf("%s%c", s[sta[i]].ori, " \n"[i == 0]);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <stack>
#include <cstring>
#include <queue>
#include <algorithm>
#include <set>
#include <cmath>
#include <map>
#include <unordered_map>
//#define lson x<<1
//#define rson x<<1|1
//#define mid ((lt[x].l+lt[x].r)/2)
//#define ID(x, y) ((x)*m+(y))
//#define CHECK(x, y) ((x)>=0 && (x)<n && (y)>=0 && (y)<m)
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
typedef unsigned long long ULL;
typedef pair<ULL, ULL> PUU;
const LL INF=0x3f3f3f3f;
void Open()
{
    #ifndef ONLINE_JUDGE
        freopen("F:/in.txt","r",stdin);
        //freopen("F:/my.txt","w",stdout);
    #endif // ONLINE_JUDGE
}
const LL N = 10010;
const LL MAGIC = 179;
char str[N], sss[N];
ULL base[N];
ULL h[N];
ULL rh[N];
map<PUU, string> m;
map<PUU, string> m1;

inline void init_hash(char *s, ULL *h, LL l)
{
    h[0]= 0;
    for(LL i = 1; i <= l;++i)
        h[i] = h[i-1] * MAGIC + s[i-1] - 'a';
    base[0] = 1;
    for(LL i = 1; i <= l; ++i)
        base[i] = base[i-1] * MAGIC;
}
inline ULL string_hash(ULL *h, LL l, LL r) //[0-base)
{
    return h[r] - h[l] * base[r-l];
}
struct word
{
    char ori[1111];
    char cur[1111];
    ULL hvalue;
    void update(LL id)
    {
        strcpy(cur, ori);
        LL len = strlen(cur);
        for(LL i = 0; i < len; i++)
            if(cur[i] > 'z' || cur[i] < 'a')
                cur[i] -= 'A' - 'a';
        reverse(cur, cur+len);
        hvalue = 0;
        for(LL i = 1; i <= len;i++)
            hvalue = hvalue * MAGIC + cur[i-1] - 'a';
        ULL rvalue = 0;
        for(int i = len; i >= 1; i--)
            rvalue = rvalue * MAGIC + cur[i-1] - 'a';
        if(m.find(PUU(hvalue, rvalue)) != m.end() && string(cur).compare(m[PUU(hvalue, rvalue)])) hvalue /= 0;
        m[PUU(hvalue, rvalue)] = string(cur);
        m1[PUU(hvalue, rvalue)] = string(ori);
    }
}s[N*10];
string pre[N];
string sta[N*10];
int main()
{
    //Open();
    //memset(pre, 0, sizeof(pre));
    LL len = 0;
    scanf("%I64d", &len);
    scanf("%s", str);
    LL n;
    scanf("%I64d", &n);
    int ma = 0;
    for(LL i = 0; i < n; i++)
    {
        scanf("%s", s[i].ori);
        s[i].update(i);
        ma = max(ma, strlen(s[i].ori))
    }
    init_hash(str, h, len);
    reverse(str, str+len);
    init_hash(str, rh, len);
    reverse(str, str+len);
    for(LL i = 0; i < len; i++)
    {
        for(LL j = max(0, j - ma - 1); j <= i; j++)
        {
            if(m1.find(PUU(string_hash(h, j, i+1), string_hash(rh, len-i-1, len-j))) != m1.end() && (j == 0 || !pre[j-1].empty()))
            {
                //cout<<m[string_hash(h, j, i+1)]<<endl;
                pre[i] = m1[PUU(string_hash(h, j, i+1), string_hash(rh, len-i-1, len-j))];
                break;
            }
        }
    }
    LL tail = 0;
    LL idx = len-1;
    while(true)
    {
        if(idx < 0) break;
        sta[tail++] = pre[idx];
        if(idx + 1 == pre[idx].length()) break;
        else idx -= pre[idx].length();

    }
    for(LL i = tail-1; i>= 0; i--)
        printf("%s%c", sta[i].c_str(), " \n"[i == 0]);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <stack>
#include <cstring>
#include <queue>
#include <algorithm>
#include <set>
#include <cmath>
#include <map>
#include <unordered_map>
//#define lson x<<1
//#define rson x<<1|1
//#define mid ((lt[x].l+lt[x].r)/2)
//#define ID(x, y) ((x)*m+(y))
//#define CHECK(x, y) ((x)>=0 && (x)<n && (y)>=0 && (y)<m)
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int INF=0x3f3f3f3f;
void Open()
{
    #ifndef ONLINE_JUDGE
        freopen("F:/in.txt","r",stdin);
        //freopen("F:/my.txt","w",stdout);
    #endif // ONLINE_JUDGE
}
const int N = 10010;
const int MAGIC = 171;
char str[N], sss[N];
unsigned int base[N];
unsigned int h[N];
unordered_map<unsigned int, int> m;
inline void init_hash(char *s, unsigned int *h, int l)
{
    h[0]= 0;
    for(int i = 1; i <= l;++i)
        h[i] = h[i-1] * MAGIC + s[i-1] - 'a';
    base[0] = 1;
    for(int i = 1; i <= l; ++i)
        base[i] = base[i-1] * MAGIC;
}
inline unsigned int string_hash(unsigned *h, int l, int r) //[0-base)
{
    return h[r] - h[l]* base[r-l];
}
struct word
{
    char ori[1111];
    char cur[1111];
    unsigned int hvalue;
    void update(int id)
    {
        strcpy(cur, ori);
        int len = strlen(cur);
        for(int i = 0; i < len; i++)
            if(cur[i] > 'z' || cur[i] < 'a')
                cur[i] -= 'A' - 'a';
        reverse(cur, cur+len);
        hvalue = 0;
        for(int i = 1; i <= len;i++)
            hvalue = hvalue * MAGIC + cur[i-1] - 'a';
        m[hvalue] = id;
    }
}s[N*10];
int pre[N], sta[N*10];
int main()
{
    //Open();
    memset(pre, -1, sizeof(pre));
    int len = 0;
    scanf("%d", &len);
    scanf("%s", str);
//    strcpy(sss, str);
//    reverse(sss, sss+len);
//    cout<<str<<endl;
//    cout<<sss<<endl;
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    {
        scanf("%s", s[i].ori);
        s[i].update(i);
    }
    init_hash(str, h, len);
    for(int i = 0; i < len; i++)
    {
        for(int j = 0; j <= i; j++)
        {
            if(m.find(string_hash(h, j, i+1)) != m.end() && (j == 0 || pre[j-1] != -1))
            {
                pre[i] = m[string_hash(h, j, i+1)];
                break;
            }
        }
    }
    int tail = 0;
    int idx = len-1;
    while(true)
    {
        if(idx < 0) break;
        sta[tail++] = pre[idx];
        if(idx + 1 == strlen(s[pre[idx]].cur)) break;
        else idx -= strlen(s[pre[idx]].cur);

    }
    for(int i = tail-1; i>= 0; i--)
        printf("%s%c", s[sta[i]].ori, " \n"[i == 0]);
    return 0;
}