#include<cstdio>
#include<cstring>
struct edge
{char c;
struct node *next;};
struct P
{int b;
char *a;};
typedef struct node
{int d,mpn,od,ann;
struct node *fn,**an;
char **mp;
edge *o;}N_t;
N_t *r,*next,*thiz=new N_t;
int i,n,b[101],j,k,o[101],l;
char s[1000001],a[101][10002],c[102];
P d[101];
N_t *find_next(N_t *thiz,char c)
{for(int i=0;i<thiz->od;i++)
if(thiz->o[i].c==c)
return thiz->o[i].next;
return NULL;}
void set_failure(N_t *thiz,N_t *node,char c[])
{for(int i=1;i<node->d;i++)
{N_t *m=thiz;
for(int j=i;j<node->d&&m;j++)
m=find_next(m,c[j]);
if(m)
{node->fn=m;
break;}}
if(!node->fn)
node->fn=thiz;}
void traverse_setfailure(N_t *thiz,N_t *node,char c[])
{for(int i=0;i<node->od;i++)
{c[node->d]=node->o[i].c;
set_failure(thiz,node->o[i].next,c);
traverse_setfailure(thiz,node->o[i].next,c);}}
int main()
{freopen("ahocorasick.in","r",stdin),freopen("ahocorasick.out","w",stdout);
gets(s),scanf("%d\n",&n);
memset(thiz,0,sizeof(N_t));
thiz->o=new edge[3];
thiz->mp=new char*[102];
thiz->an=new N_t*[10002];
thiz->an[thiz->ann++]=thiz;
for(j=1;j<=n;j++)
{gets(a[j]),r=thiz;
for(i=1;i<j&&!o[j];i++)
if(!strcmp(a[j],a[i]))
o[j]=i;
if(!o[j])
{for(i=0;a[j][i];i++)
if((next=find_next(r,a[j][i])))
r=next;
else
{next=new N_t,memset(next,0,sizeof(N_t)),next->o=new edge[3];
next->mp=new char*[102],r->o[r->od].c=a[j][i];
r->o[r->od++].next=next,next->d=r->d+1;
thiz->an[thiz->ann++]=r=next;}
r->mp[r->mpn++]=a[j];}}
traverse_setfailure(thiz,thiz,c);
for(i=1;i<=n;i++)
if(!o[i])
d[l].a=a[i],d[l++].b=i;
while(s[k])
if(!(next=find_next(thiz,s[k])))
if(thiz->fn)
thiz=thiz->fn;
else
k++;
else
{thiz=next,k++;
for(i=0;i<l;i++)
for(j=0;j<thiz->mpn;j++)
if(thiz->mp[j]==d[i].a)
b[d[i].b]++;}
for(i=1;i<=n;i++)
printf("%d\n",!o[i]?b[i]:b[o[i]]);
return 0;}