#include <bits/stdc++.h>
using namespace std;
int n,i,a[26],b[26];
vector<string> r;
char s[44];
int main() {
  scanf("%s",s);
  for (i=0; s[i]; i++) a[s[i]-'a']++;
  scanf("%d",&n);
  while (n--) {
    for (i=0; i<26; i++) b[i]=0;
    scanf("%s",s);
    for (i=0; s[i]; i++) b[s[i]-'a']++;
    for (i=0; i<26; i++) if (b[i]>a[i]) break;
    if (i>=26) r.push_back(s);
  }
  sort(r.begin(),r.end());
  for (i=0; i<r.size(); i++) printf("%s\n",r[i].c_str());
  return 0;
}