#P1207G. Indie Album
Indie Album
No submission language available for this problem.
Description
Mishka's favourite experimental indie band has recently dropped a new album! Songs of that album share one gimmick. Each name is one of the following types:
- — a single lowercase Latin letter;
- — name () with a single lowercase Latin letter appended to its end.
Songs are numbered from to . It's guaranteed that the first song is always of type .
Vova is rather interested in the new album but he really doesn't have the time to listen to it entirely. Thus he asks Mishka some questions about it to determine if some song is worth listening to. Questions have the following format:
- — count the number of occurrences of string in (the name of the -th song of the album) as a continuous substring, consists only of lowercase Latin letters.
Mishka doesn't question the purpose of that information, yet he struggles to provide it. Can you please help Mishka answer all Vova's questions?
The first line contains a single integer () — the number of songs in the album.
Each of the next lines contains the desciption of the -th song of the album in the following format:
- — is a single lowercase Latin letter;
- — is the name () with a single lowercase Latin letter appended to its end.
The next line contains a single integer () — the number of Vova's questions.
Each of the next lines contains the desciption of the -th Vova's question in the following format:
- (, ) — count the number of occurrences of string in (the name of the -th song of the album) as a continuous substring, consists only of lowercase Latin letters.
It's guaranteed that the total length of question strings doesn't exceed .
For each question print a single integer — the number of occurrences of the question string in the name of the -th song of the album as a continuous substring.
Input
The first line contains a single integer () — the number of songs in the album.
Each of the next lines contains the desciption of the -th song of the album in the following format:
- — is a single lowercase Latin letter;
- — is the name () with a single lowercase Latin letter appended to its end.
The next line contains a single integer () — the number of Vova's questions.
Each of the next lines contains the desciption of the -th Vova's question in the following format:
- (, ) — count the number of occurrences of string in (the name of the -th song of the album) as a continuous substring, consists only of lowercase Latin letters.
It's guaranteed that the total length of question strings doesn't exceed .
Output
For each question print a single integer — the number of occurrences of the question string in the name of the -th song of the album as a continuous substring.
Samples
Note
Song names of the first example:
- d
- da
- dad
- dada
- dadad
- dadada
- dadadad
- dadadada
- d
- do
- dok
- doki
- dokid
- dokido
- dokidok
- dokidoki
- do
- dok
- doki
- dokidoki
Thus the occurrences for each question string are:
- string "da" starts in positions in the name "dadadada";
- string "dada" starts in positions in the name "dadadada";
- string "ada" starts in positions in the name "dadadada";
- string "dada" starts in positions in the name "dadada";
- no occurrences of string "dada" in the name "dad";
- string "doki" starts in position in the name "doki";
- string "ok" starts in position in the name "doki";
- string "doki" starts in positions in the name "dokidoki";
- string "doki" starts in position in the name "dokidok";
- string "d" starts in position in the name "d";
- no occurrences of string "a" in the name "d";
- string "doki" starts in positions in the name "dokidoki".