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

string word;
string t;

int main()
{
    cin >> word;

    int n;
    cin >> n;

    for(int i=0; i<n; i++)
    {
        cin >> t;
        int index=word.find(t);
        int eindex;
        if(index!=string::npos)
        {
            eindex=index+t.size()-1;
            //cout << index << " " << t.size() << " " << eindex << endl;
            word.erase(5, t.size());
            //cout << word;
        }

    }

    cout << word;



    return 0;
}
