Responsive image

问题 A: String

问题 A: String

时间限制: 15 Sec  内存限制: 900 MB
提交: 23  解决: 11
[提交][状态][讨论版][命题人:]

题目描述

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.

输入描述

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|≤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|≤100000,0<|Pi|+|Si|≤100000)
All of the above characters are lowercase letters.
The dictionary does not contain the same words.

Limits
T≤5
0<N,Q≤100000
∑Si+Pi≤500000
∑Wi≤500000

输出描述

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

样例输入

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

样例输出

2
1
1
0
[提交][状态]
ACM算法攻关部