#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
string s, s1;
string s2[100003];
int n, m, p; // m - s.size; p - s1
int main()
{
    cin >> s;
    cin >> n;
    for(int i = 0; i < n; i ++) cin >> s2[i];
    bool tf = 1;
    while(tf == 1)
    {
        tf = 0;
        for(int i = 0; i < n; i ++)
        {
            s1 = s2[i];
            m = s.size();
            p = 0;
            for(int j = 0; j < m; j ++)
            {
                if(p == s1.size())
                {
                    s.erase(j-p,p);
                    j -= p;
                    p = 0;
                    tf = 1;
                }
                if(s1[p] == s[j])
                {
                    p ++;
                }
                else if(s1[p] != s[j]) p = 0;
            }
        }
    }
    cout << s << endl;
    return 0;
}
