# Include <cstdio>
# Include <cstdlib>
# Include <cstring>
# Include <string>
# Include <iostream>
Using namespace STD;
Typedef struct TT
{
Struct TT * Next [26];
Int num;
} Tire;
Void insert (tire * P, string temp)
{
Int I = 0, J, K;
Tire * n = P, * q;
While (temp [I])
{
J = temp [I]-'A' + 1;
If (n-> next [J] = NULL)
{
Q = new tire;
Q-> num = 0;
For (k = 0; k <= 25; k ++)
Q-> next [k] = NULL;
N-> next [J] = Q;
}
N-> next [J]-> num ++;
N = N-> next [J];
I ++;
}
}
Void myfree (tire * P ){
For (INT I = 0; I <= 25; I ++ ){
If (p-> next [I]! = NULL ){
Myfree (p-> next [I]);
}
}
Delete P;
Return;
}
Int getnode (tire * P, string temp)
{
Int I = 0, J;
Tire * n = P;
While (temp [I])
{
J = temp [I]-'A' + 1;
If (n-> next [J] = NULL)
{
Return 0;
}
Else
{
N = N-> next [J];
}
I ++;
}
Return N-> num;
}
Int main ()
{
Int I;
Tire * root = new tire;
Root-> num = 0;
For (I = 0; I <= 25; I ++)
Root-> next [I] = NULL;
Int N;
String temp;
// Char temp [11];
// Scanf ("% d", & N );
Cin> N;
While (n --)
{
Cin> temp;
// Scanf ("% s", temp );
Insert (root, temp );
}
Cin> N;
// Scanf ("% d", & N );
While (n --)
{
Cin> temp;
// Scanf ("% s", temp );
Cout <getnode (root, temp) <Endl;
// Printf ("% d \ n", getnode (root, temp ));
}
Myfree (Root );
Return 0;
}
Microsoft hiho dictionary tree count prefix count