1 #include <bits/stdc++.h>
2 using namespace std;
3
4 const int maxn=1000+5,maxm=100+5,maxl=30+5;
5 int n,m;
6 int t[maxn][maxn],p[maxm][maxl];
7 char c;
8 char s[maxn];
9 inline bool match(int x,int y){
10 int l1=t[x][0],l2=p[y][0],i,j;
11 for(i=1,j=1;i<=l1&&j<=l2;i++)if(t[x][i]==p[y][j]) j++;
12 return j>l2;
13 }
14 int main(){
15 scanf("%d%d",&n,&m);
16 for(int i=1;i<=n;i++){
17 scanf("%s",s+1); int l=strlen(s+1); t[i][0]=l;
18 for(int j=1;j<=l;j++) t[i][j]=s[j]>=‘a‘&&s[j]<=‘z‘?s[j]-‘a‘:s[j]-‘A‘;
19 }
20 for(int i=1;i<=m;i++){
21 scanf("%s",s+1); int l=strlen(s+1); p[i][0]=l;
22 for(int j=1;j<=l;j++) p[i][j]=s[j]>=‘a‘&&s[j]<=‘z‘?s[j]-‘a‘:s[j]-‘A‘;
23 }
24 for(int i=1;i<=n;i++){
25 int ans=0;
26 for(int j=1;j<=m;j++)if(match(i,j)) ans++;
27 printf("%d\n",ans);
28 }
29 return 0;
30 }