#include <iostream>
using namespace std;
const int MAXN=1e5+10;
int tr[MAXN][32], f[MAXN], w[MAXN], par[MAXN][2];
int cnt=1;
string word[MAXN];
char res[MAXN];
void add(int j) {
    int ind=1, let;
    for (int i=0;i<word[j].size();i++) {
        let=word[j][i]-'a';
        if (tr[ind][let]==0) {
            cnt++;
            tr[ind][let]=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() {
    f[1]=1;
    for (int i=2;i<=cnt;i++) {
        if (par[i][0]==1) {
            f[i]=1;
            continue;
        }
        int let=par[i][1];
        int ind=par[i][0];
        while (ind>1) {
            ind=f[ind];
            if (tr[ind][let]!=0) {
                ind=tr[ind][let];
                break;
            }
            if (ind==1) break;
            ind=par[ind][0];
        }
        f[i]=ind;
    }
}
void find_str(string s) {
    int ind=1, let, br=0;
    for (int i=0;i<s.size();i++,br++) {
        res[br]=s[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) {
            br-=w[ind];
            ind=1;
        }
    }
    for (int i=0;i<br;i++) cout << res[i];
    cout << endl;
}
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);
    }
    connect();
    find_str(s);
    return 0;
}
/**
cococok
1
cocok
**/
