#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int MAXN=1e5+5;
const int MAXS=1e5+5;
const int BASE=137; ///
const int MOD=1e9+7; ///
string s;
int n;
string w[MAXN];
set<int> len;
set<long long> wl[MAXN];
long long ht[MAXS];
long long bpw[MAXS];
string ans="";
int Hash(string str)
{
    int res=0;
    for(int i=0;i<str.size();i++)
    {
        res=((long long)res*BASE+str[i])%MOD;
    }
    return res;
}
void precomp()
{
    bpw[0]=1;
    for(int i=1;i<MAXS;i++)
    {
        bpw[i]=(long long)bpw[i-1]*BASE%MOD;
    }
    ht[0]=s[0];
    //cout<<ht[0];
    for(int i=1;i<s.size();i++)
    {
        ht[i]=((long long)ht[i-1]*BASE+s[i])%MOD;
        //cout<<" "<<ht[i];
    }
    //cout<<endl;
}
int subhash(int l,int r)
{
    int hl= ((l>0) ? ht[l-1] : 0);
    int hr=ht[r];
    hl=(long long)hl*bpw[r-l+1]%MOD;
    return (hr-hl+MOD)%MOD;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>s;
cin>>n;
for(int i=0;i<n;i++)
{
    cin>>w[i];
    len.insert((int)w[i].size());
    wl[(int)w[i].size()].insert(Hash(w[i]));
    //cout<<Hash(w[i])<<endl;
}
precomp();
//cout<<subhash(11,13)<<endl;
for(int i=0;i<s.size();)
{
    int fl=0;
    for(auto it=len.begin();it!=len.end();it++)
    {
        int subh=subhash(i,i+(*it)-1);
        if(wl[(*it)].count(subh))
        {
            fl=(*it);
            break;
        }
    }
    if(!fl) {ans=ans+s[i]; i++;}
    else i=i+fl;
}
cout<<ans<<endl;
return 0;
}
