#P1608G. Alphabetic Tree
Alphabetic Tree
Description
You are given strings and a tree on nodes. Each edge has some letter written on it.
You have to answer queries. Each query is described by integers , , and . The answer to the query is the total number of occurrences of in strings with indices from to . is defined as the string that is made by concatenating letters written on the edges on the shortest path from to (in order that they are traversed).
The first line of the input contains three integers , and (, ).
The -th of the following lines contains two integers and a lowercase Latin letter (, ), denoting the edge between nodes with a character on it.
It's guaranteed that these edges form a tree.
The following lines contain the strings consisting of lowercase Latin letters. The total length of those strings does not exceed .
Then lines follow, each containing four integers , , and (, , ), denoting the queries.
For each query print a single integer — the answer to the query.
Input
The first line of the input contains three integers , and (, ).
The -th of the following lines contains two integers and a lowercase Latin letter (, ), denoting the edge between nodes with a character on it.
It's guaranteed that these edges form a tree.
The following lines contain the strings consisting of lowercase Latin letters. The total length of those strings does not exceed .
Then lines follow, each containing four integers , , and (, , ), denoting the queries.
Output
For each query print a single integer — the answer to the query.