/*
* BDFHJK
* Sun, 17 Apr 2011 11:40:24 +0200
*/
#include<string>
#include<list>
#include<deque>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<utility>
#include<sstream>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<iostream>
using namespace std;
//#define DEBUG 1
#define FOR(I,A,B) for(int I=(A);I<=(B);I++)
#define REP(I,N) for(int I=0;I<(N);I++)
#define ALL(X) (X).begin(),(X).end()
#define FORD(I,A,B) for(int I=(A);I>=(B);I--)
#define INF ((int)1e9)
#define VAR(V,init) __typeof(init) V=(init)
#define FOREACH(I,C) for(VAR(I,(C).begin());I!=(C).end();I++)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define MOD ((int)1e9+7)
typedef vector< int > VI;
typedef pair< int ,int > PII;
typedef long long LL;
typedef vector< string> VS;
LL nwd( LL a, LL b) { return ! b? a: nwd( b,a% b) ; }
int t, N, K;
string SJ[ ( ( int ) 1e5 + 7 ) ] ;
string SP[ ( ( int ) 1e5 + 7 ) ] ;
int W[ ( ( int ) 1e5 + 7 ) ] ;
void licz( int l, int p)
{
vector< pair< string, int > > PO;
vector< string> SJV;
REP( i, N)
{
//Słowo musi mieć przynajmniej l+p znaków
if ( SJ[ i] .size ( ) >= l+ p)
{
string temp = "" ;
REP( j, l) temp+ = SJ[ i] [ j] ;
REP( j, p) temp+ = SJ[ i] [ SJ[ i] .size ( ) - ( p- j) ] ;
SJV.push_back ( temp) ;
#ifdef DEBUG
cout << "SJIN: " << temp << endl;
#endif
}
}
stable_sort( SJV.begin ( ) , SJV.end ( ) ) ;
REP( i, K)
{
if ( SP[ i] .size ( ) == p+ l+ 1 )
{
int lzl= 0 ;
while ( SP[ i] [ lzl] ! = '*' ) lzl++ ;
int pzl= SP[ i] .size ( ) - lzl - 1 ;
if ( lzl ! = l || pzl ! = p) continue ;
string temp = SP[ i] ;
temp.erase ( lzl,1 ) ;
PO.PB ( MP( temp, i) ) ;
#ifdef DEBUG
cout << "SPIN" << i << " " << " " << temp << endl;
#endif
}
}
vector< string> :: iterator low, up;
REP( i, PO.size ( ) )
{
low = lower_bound( ALL( SJV) , PO[ i] .FI ) ;
up = upper_bound( ALL( SJV) , PO[ i] .FI ) ;
W[ PO[ i] .SE ] = int ( up- low) ;
#ifdef DEBUG
printf ( "W[%d] = %d\n " , PO[ i] .SE , W[ PO[ i] .SE ] ) ;
#endif
}
}
int main( )
{
scanf ( "%d\n " , & t) ;
REP( zi, t)
{
scanf ( "%d\n " , & N) ;
REP( i, N) cin >> SJ[ i] ;
scanf ( "%d\n " , & K) ;
REP( i, K) cin >> SP[ i] ;
sort( SJ, SJ+ N) ;
//i - liczba znaków przed gwiazdką, j - liczba znaków po gwiazdce
REP( i, 10 ) REP( j, 10 ) licz( i, j) ;
REP( i, K) printf ( "%d\n " , W[ i] ) ;
}
}
LyoKICogQkRGSEpLCiAqIFN1biwgMTcgQXByIDIwMTEgMTE6NDA6MjQgKzAyMDAKICovCiAKIAojaW5jbHVkZTxzdHJpbmc+CiNpbmNsdWRlPGxpc3Q+CiNpbmNsdWRlPGRlcXVlPgojaW5jbHVkZTxtYXA+CiNpbmNsdWRlPHNldD4KI2luY2x1ZGU8cXVldWU+CiNpbmNsdWRlPHN0YWNrPgojaW5jbHVkZTx1dGlsaXR5PgojaW5jbHVkZTxzc3RyZWFtPgojaW5jbHVkZTxjc3RyaW5nPgojaW5jbHVkZTxjbWF0aD4KI2luY2x1ZGU8Y3N0ZGxpYj4KI2luY2x1ZGU8YWxnb3JpdGhtPgojaW5jbHVkZTx2ZWN0b3I+CiNpbmNsdWRlPGNzdGRpbz4KI2luY2x1ZGU8aW9zdHJlYW0+CiAKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKIAovLyNkZWZpbmUgREVCVUcgMQojZGVmaW5lIEZPUihJLEEsQikgZm9yKGludCBJPShBKTtJPD0oQik7SSsrKQojZGVmaW5lIFJFUChJLE4pIGZvcihpbnQgST0wO0k8KE4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CIlZFxuIiwgJk4pOyAKCQlSRVAoaSwgTikgY2luID4+IFNKW2ldOwoJCXNjYW5mKCIlZFxuIiwgJkspOwoJCVJFUChpLCBLKSBjaW4gPj4gU1BbaV07CiAKCQlzb3J0KFNKLCBTSitOKTsKIAoJCS8vaSAtIGxpY3piYSB6bmFrw7N3IHByemVkIGd3aWF6ZGvEhSwgaiAtIGxpY3piYSB6bmFrw7N3IHBvIGd3aWF6ZGNlCgkJUkVQKGksIDEwKSBSRVAoaiwgMTApIGxpY3ooaSwgaik7CiAKCQlSRVAoaSwgSykgcHJpbnRmKCIlZFxuIiwgV1tpXSk7Cgl9Cn0=
compilation info
prog.cpp: In function ‘void licz(int, int)’:
prog.cpp:61: warning: comparison between signed and unsigned integer expressions
prog.cpp:76: warning: comparison between signed and unsigned integer expressions
prog.cpp:93: warning: comparison between signed and unsigned integer expressions
prog.cpp: In function ‘int main()’:
prog.cpp:108: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
prog.cpp:111: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
prog.cpp:113: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
stdout