How Many Schemes
题号:NC51640
时间限制:C/C++/Rust/Pascal 3秒,其他语言6秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
64bit IO Format: %lld

题目描述

Gromah and LZR have entered the eighth level. There is an -vertex tree, acyclic bidirectional connected graph painted on the wall. The vertices are conveniently labeled with .

LZR finds that for every edge  in the tree, there is a non-empty set of lowercase letters s_e above it. Meanwhile, Gromah finds strings  and  queries  beside the tree.

Soon, LZR finds a note board saying that for each query , you may choose exactly one letter from s_e for all edges  in the chain  and write down the chosen letters in the order of the directed chain  to form a string , and the answer to this query is the number of schemes to choose letters so that the result string  completely contains at least one of the  given strings .

Moreover, the answers to queries may be very large, so they only need to know the answers modulo .

Please help them answer the queries to enter the next level.

输入描述:

The first line contains three positive integers , denoting the size of the tree, the number of given strings and the number of queries.

Following  lines each contains two positive integers  and a string str_e, denoting an edge between  and  with a set  above it.

Following  lines each contains a string t_i.

Following  lines each contains two positive integers , denoting a query .



The given graph forms a tree.

str_e only contains pairwise distinct lowercase letters.

t_i only contains lowercase letters.

 for all queries.

输出描述:

Output  lines, each contains one non-negative integer denoting the answer to corresponding query modulo .
示例1

输入

复制
5 2 3
1 2 nkei
1 3 ieu
2 4 nk
2 5 ne
niu
ke
3 4
4 3
3 5

输出

复制
0
6
3

说明

For the first query, there is no valid scheme.

For the second query, the 6 result strings are niu, nke, kke, kei, kee, keu_{}.

For the third query, the 3 result strings are ike, eke, uke_{}.