#include #include #include #include using namespace std; int freq[26]; int freq2[26]; int main() { string s; cin >> s; int n; cin >> n; for ( int i = 0; i < s.size(); ++i ) freq[s[i] - 'a']++; string word; for ( int i = 0; i < n; ++i ) { cin >> word; for ( int j = 0; j < 26; ++j ) freq2[j] = 0; for ( int j = 0; j < (int)word.size(); ++j ) freq2[word[j] - 'a']++; bool ok = true; for ( int j = 0; j < 26; ++j ) if ( freq[j] < freq2[j] ) ok = false; if ( ok ) cout << word << "\n"; } }