#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long int lld; typedef pair PII; const int INF = (1<<31)-1; const lld LINF = (1LL<<63)-1; const int NMAX = 100000+5; const int MMAX = 100000+5; const int KMAX = 100000+5; const int PMAX = 100000+5; const int LMAX = 100000+5; const int VMAX = 100000+5; char S[50],P[70005][50],*p; int N,M,i; int Fr[50],C[50]; vector V; bool fml(int a,int b) { if(strcmp(P[a],P[b])<=0) return 1; return 0; } int main() { //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); scanf("%s",S); for(p=S; *p; p++) Fr[*p-'a']++; scanf("%d",&N); for(int j=1; j<=N; j++) { scanf("%s",P[j]); memset(C,0,sizeof(C)); for(p=P[j]; *p; p++) C[*p-'a']++; for(i=0; i<26; i++) if(C[i] > Fr[i]) break; if(i==26) V.push_back(j); } sort(V.begin(),V.end(),fml); for(vector::iterator it=V.begin(); it!=V.end(); it++) printf("%s\n",P[*it]); return 0; }