#include < iostream >
#include
< cstring >
using   namespace  std;
struct  Trie
{
    Trie 
* next[ 26 ];
    
int  cnt;
};
Trie 
* head;
char  tmp[ 15 ];
int  build()
{
    head
= new  Trie;
    
int  i;
    
for (i = 0 ;i < 26 ;i ++ )
    {
        head
-> next[i] = NULL;
    }
    head
-> cnt = 0 ;
    
return   0 ;
}
int  insert( char  c[])
{
    
int  i,j;
    Trie 
* t, * s = head;
    
int  len = strlen(c);
    
for (i = 0 ;i < len;i ++ )
    {
        
if (s -> next[c[i] - ' a ' ] == NULL)
        {
            t
= new  Trie;
            
for (j = 0 ;j < 26 ;j ++ )
            {
                t
-> next[j] = NULL;
            }
            t
-> cnt = 0 ;
            s
-> next[c[i] - ' a ' ] = t;
           
        }
        s
= s -> next[c[i] - ' a ' ];
        s
-> cnt ++ ;
    }
    
return   0 ;
}
int  check( char  c[])
{
    
int  count;
    
int  i,j;
    Trie 
* s = head;
    
int  len = strlen(c);
    
for (i = 0 ;i < len;i ++ )
    {
        
if (s -> next[c[i] - ' a ' ] == NULL)
        {  
            count
= 0 ;
            
return  count;
        }
        
else
        {    
            s
= s -> next[c[i] - ' a ' ];
            count
= s -> cnt;
        }
    }
    
return  count;
}
int  main()
{
    build();
    
while (gets(tmp),strcmp(tmp, "" ))
    {
        insert(tmp);
    }
    
while (gets(tmp))
    {
        cout
<< check(tmp) << endl;
    }
    
// system("pause");
     return   0 ;
}