#include<bits/stdc++.h>
using namespace std;

const int maxn=100003;
string s;
string t[maxn];
int n;
unsigned long long curr=0, from=0;

unsigned long long seg(string x){
    unsigned long long ans=0;
    for(int i=0; i<x.size(); i++){
        ans*=26;
        ans=ans + (x[i]-'a');
    }
    return ans*26;
}

string shift(string x, int fr, int ind){
    string ans;
    ans.resize(x.size()+40);
    for(int i=0; i<fr; i++){
        ans[i]=x[i];
    }
    for(int i=ind; i<x.size();i++){
        ans[i-(ind-fr)]=x[i];
    }
    return ans;
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);


cin>>s;
cin>>n;
for(int i=0; i<n; i++){
    cin>>t[i];
    curr=seg(t[i]);
    unsigned long long p=0;
    unsigned long long step=1;
    for(int j=0; j<t[i].size(); j++){
            p*=26;
            step*=26;
            p+=s[j]-'a';
    }
    p*=26;
    //cerr<<"step="<<step<<endl;
    //cerr<<"curr="<<curr<<endl;
    //cerr<<"ot 0 do "<<t[i].size()-1<<" : "<<p<<endl;
    if(p==curr){
        s=shift(s, 0, t[i].size());
       // cerr<<"da"<<endl;
        //cout<<s<<endl;
    }
    for(int j=t[i].size(); j<s.size(); j++){
            p%=step;
            p+=s[j]-'a';
            p*=26;
            //cerr<<"ot "<<j-(t[i].size()-1)<<" do "<<j<<" : "<<p<<endl;
            if(p==curr){
                //cerr<<"da"<<endl;
               s=shift(s, j-t[i].size()+1, j+1);
               j-=t[i].size();
               //cout<<s<<endl;
            }
    }
}
int m=0;
while(s[m]<='z' and s[m]>='a'){
    cout<<s[m];
    m++;
}

return 0;
}
