#P1608G. Alphabetic Tree

    ID: 1585 Type: RemoteJudge 3000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 10 Uploaded By: Tags>binary searchdata structuresdfs and similarhashingstring suffix structuresstringstrees*3500

Alphabetic Tree

Description

You are given mm strings and a tree on nn nodes. Each edge has some letter written on it.

You have to answer qq queries. Each query is described by 44 integers uu, vv, ll and rr. The answer to the query is the total number of occurrences of str(u,v)str(u,v) in strings with indices from ll to rr. str(u,v)str(u,v) is defined as the string that is made by concatenating letters written on the edges on the shortest path from uu to vv (in order that they are traversed).

The first line of the input contains three integers nn, mm and qq (2n1052 \le n \le 10^5, 1m,q1051 \le m,q \le 10^5).

The ii-th of the following n1n-1 lines contains two integers ui,viu_i, v_i and a lowercase Latin letter cic_i (1ui,vin1 \le u_i, v_i \le n, uiviu_i \neq v_i), denoting the edge between nodes ui,viu_i, v_i with a character cic_i on it.

It's guaranteed that these edges form a tree.

The following mm lines contain the strings consisting of lowercase Latin letters. The total length of those strings does not exceed 10510^5.

Then qq lines follow, each containing four integers uu, vv, ll and rr (1u,vn1 \le u,v \le n, uvu \neq v, 1lrm1 \le l \le r \le m), 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 nn, mm and qq (2n1052 \le n \le 10^5, 1m,q1051 \le m,q \le 10^5).

The ii-th of the following n1n-1 lines contains two integers ui,viu_i, v_i and a lowercase Latin letter cic_i (1ui,vin1 \le u_i, v_i \le n, uiviu_i \neq v_i), denoting the edge between nodes ui,viu_i, v_i with a character cic_i on it.

It's guaranteed that these edges form a tree.

The following mm lines contain the strings consisting of lowercase Latin letters. The total length of those strings does not exceed 10510^5.

Then qq lines follow, each containing four integers uu, vv, ll and rr (1u,vn1 \le u,v \le n, uvu \neq v, 1lrm1 \le l \le r \le m), denoting the queries.

Output

For each query print a single integer — the answer to the query.

Sample Input 1

2 5 3
1 2 a
aab
abab
aaa
b
a
2 1 1 5
1 2 1 3
2 1 3 5

Sample Output 1

8
7
4

Sample Input 2

9 5 6
1 2 a
2 7 c
1 3 b
3 4 b
4 6 b
3 5 a
5 8 b
5 9 c
ababa
cabbb
bac
bbbac
abacaba
2 7 1 4
2 5 1 5
6 3 4 4
6 9 4 5
5 7 3 5
5 3 1 5

Sample Output 2

3
4
2
1
1
10