#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN=2e5+10;
int tr[MAXN][32], d[MAXN], f[MAXN], ok[MAXN], w[MAXN], par[MAXN][2], mem[MAXN];
pair <int,int> num[MAXN];
int cnt=1;
string word[MAXN];
char res[MAXN];
void add(int j) {
    int ind=1, let;
    d[1]=0;
    num[1]={0,1};
    for (int i=0;i<word[j].size();i++) {
        let=word[j][i]-'a';
        if (tr[ind][let]==0) {
            cnt++;
            tr[ind][let]=cnt;
            d[cnt]=d[ind]+1;
            num[cnt].second=cnt;
            num[cnt].first=d[cnt];
            par[cnt][0]=ind;
            par[cnt][1]=let;
        }
        ind=tr[ind][let];
        if (i==word[j].size()-1) w[ind]=word[j].size();
    }
}
void connect() {
    for (int j=1;j<=cnt;j++) {
        int i=num[j].second;
        if (i==1 || par[i][0]==1) {
            f[i]=ok[i]=1;
            continue;
        }
        int let=par[i][1], ind=par[i][0];
        while (ind>1) {
            ind=f[ind];
            if (tr[ind][let]!=0) {
                ind=tr[ind][let];
                break;
            }
        }
        f[i]=ind;

        if (w[f[i]]) ok[i]=f[i];
        else ok[i]=ok[f[i]];
        ///cout << i << ' ' << f[i] << ' ' << ok[i] << endl;
    }
}
string find_meet(string s) {
    int ind=1, let;
    mem[0]=1;
    for (int i=0;i<s.size();i++) {
        let=s[i]-'a';
        while (ind!=1 && tr[ind][let]==0) ind=f[ind];
        if (ind==1 && tr[ind][let]==0) continue;
        ind=tr[ind][let];
        if (w[ind]!=0) {
            s.erase(i-w[ind]+1,w[ind]);
            i-=w[ind];
            if (i==-1) ind=1;
            else ind=mem[i];
        } else mem[i]=ind;
    }
    return s;
}
int main () {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    string s;
    cin >> s >> n;
    for (int i=0;i<n;i++) {
        cin >> word[i];
        add(i);
    }
    sort(num+1,num+cnt+1);
    connect();
    cout << find_meet(s) << endl;
    return 0;
}
/**
cococokfggg
3
cocok
cokf
cof
ok
**/
