#include<bits/stdc++.h>
#pragma optimise("O3")
#pragma target("sse4")
using namespace std;
#define b 311
#define MOD 1000000007
const long long MAXN=100007;
int nn[MAXN];
string s,t[MAXN];
int n;
bitset<MAXN> sysht;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>s;
    cin>>n;
    for (int q=0;q<n;q++) cin>>t[q];
    while (true)
    {
        //cout<<s<<"\n";
        int ass=-1,ll=-1;
        for (int q=0;q<n;q++)
        {
            long long bh=1;
            for (int w=1;w<t[q].size();w++) bh=(bh*b)%MOD;
            long long og=0;
            for (int w=0;w<t[q].size();w++)
            {
                og*=b;
                og+=t[q][w];
                og%=MOD;
            }
            long long cur=0;
            for (int w=0;w<t[q].size();w++)
            {
                cur*=b;
                cur+=s[w];
                cur%=MOD;
            }
            if (cur==og)
            {
                if (ass==-1)
                {
                    ass=0;
                    ll=t[q].size();
                }
            }
            else
            {
                for (int w=t[q].size();w<s.size();w++)
                {
                    cur+=MOD;
                    cur-=(bh*s[w-t[q].size()])%MOD;
                    cur%=MOD;
                    cur*=b;
                    cur+=s[w];
                    cur%=MOD;
                    if (cur==og)
                    {
                        if (w-t[q].size()+1<ass)
                        {
                            ass=w-t[q].size()+1;
                            ll=t[q].size();
                            break;
                        }
                    }
                }
            }
        }
        if (ass==-1) break;
        else
        {
            string s1="";
            for (int q=0;q<s.size();q++)
            {
                if (q<ass || q>=(ass+ll)) s1+=s[q];
            }
            s=s1;
        }
    }
    cout<<s<<"\n";
}
