#include<iostream>
#include<string>
using namespace std;
const long long MAXN=1e5+7;
string duma[MAXN];
int main (){
    string a;

    int n;
    cin>>a;
    cin>>n;
    //a.erase(a.begin(),a.end()-3);
    for(int i=0;i<n;i++){
        cin>>duma[i];
    }
    int ind=0;
    bool fl=false;
    int best;
    int len;
    while(true){
            fl=false;
            best=a.size();
        for(int i=0;i<n;i++){
                ind=0;
            for(int j=0;j<a.size();j++){
                if(a[j]==duma[i][ind]){
                    if(ind==duma[i].size()-1){
                        //cout<<" ot "<<j-duma[i].size()+1<<"\n";
                        if(best>j-duma[i].size()+1){
                            best=j-duma[i].size()+1;
                            len=duma[i].size();
                        }
                        fl=true;
                        break;
                    }else ind++;
                }else if(a[j]==duma[i][0]){
                    ind=1;
                }else ind=0;
            }

        }

        if(!fl) break;
        //cout<<"triq ot "<<best<<"\n";
        a.erase(a.begin()+best,a.begin()+best+len);
        //cout<<a<<"\n";
    }
    cout<<a<<"\n";
    return 0;
}
