#include <bits/stdc++.h>

const int MAX_N = 1e6;

std::string a[MAX_N];

std::vector<int> len;
std::vector<std::string> v[MAX_N];

int main () {

    std::string s;
    std::cin>>s;
    int n;
    std::cin>>n;
    for( int i=0 ; i<n ; i++ ){
        std::cin>> a[i];
        int currLen = a[i].size();
        len.push_back(currLen);
        v[currLen].push_back( a[i] );
    }
    for( int k=0 ; k<10 ; k++ )
    for( int i=0 ; i<s.size() ; i++ ){
            for( int j : len ){
                std::string curr = s.substr( i, j );
   //             std::cerr<<curr<<" : ";
                for( std::string j : v[j] )
                    if( j == curr ){
                        s.erase( i, j.size() );
    //                    std::cerr<<s<<"\n";
                        break;
                    }
            }
    //        std::cerr<<"\n";
    }

    std::cout<<s<<"\n";

    return 0;
}
