#include <bits/stdc++.h>
#pragma optimize(O3)
#define endl '\n'
using namespace std;

string v[100005];

int main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    string s;
    cin >> s;
    int sz = s.size();

    int n;
    cin >> n;

    for (int i = 0; i < n; i++)
        cin >> v[i];

    while (true)
    {
        int mini = 2e9;
        int minind = 0;
        for (int i = n - 1; i >= 0; i--)
        {
            int ind = s.find(v[i]);
            if (ind == -1) continue;
            if (ind < mini)
            {
                minind = i;
                mini = ind;
            }
        }
        if (mini != 2e9) s.erase(s.begin() + mini, s.begin() + mini + v[minind].size());
        else break;
    }

    cout << s << endl;

    return 0;
}
/***
enjoycodingcppprograms
3
code
coding
cpp

-----
enjoyprograms
*/
