F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

String

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 2689    Accepted Submission(s): 837


Problem Description
Bob has a dictionary with N words in it.
Now there is a list of words in which the middle part of the word has continuous letters disappeared. The middle part does not include the first and last character.
We only know the prefix and suffix of each word, and the number of characters missing is uncertain, it could be 0. But the prefix and suffix of each word can not overlap.
For each word in the list, Bob wants to determine which word is in the dictionary by prefix and suffix.
There are probably many answers. You just have to figure out how many words may be the answer.
 

Input
The first line of the input gives the number of test cases T; T test cases follow.
Each test case contains two integer N and Q, The number of words in the dictionary, and the number of words in the list.
Next N line, each line has a string Wi, represents the ith word in the dictionary ($0 < |Wi| \leq 100000$)
Next Q line, each line has two string Pi , Si, represents the prefix and suffix of the ith word in the list ($0 < |Pi|,|Si| \leq 100000, 0 < |Pi|+|Si| \leq 100000$)
All of the above characters are lowercase letters.
The dictionary does not contain the same words.

Limits
$T \leq 5$
$0 < N,Q \leq100000$
$\sum{Si +Pi} \leq 500000$
$\sum{Wi} \leq 500000$
 

Output
For each test case, output Q lines, an integer per line, represents the answer to each word in the list.
 

Sample Input
1 4 4 aba cde acdefa cdef a a cd ef ac a ce f
 

Sample Output
2 1 1 0
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 13:01:01, Gzip enabled