SP33263 ADATOMEL - Ada and Tomel

Description

As you might already know, Ada the Ladybug is a farmer. She grows a tomel [tree](https://en.wikipedia.org/wiki/Tree_(data_structure)). Tomel indeed is a very specific tree. Its growing process starts with one root node with a fruit of random flavor. Whenever a next branch grows, it begins to grow from a random node which is already grown up. No growing starts until the branch is fully grown. As a branch fully grows up, a node with fruit with random flavor appears at the end of the branch. As you surely haven't heard word random for a long time, Ada chooses three random paths and wants to find the number of distinct flavors which grow on the union of these three paths. **NOTE:** Every random mentioned above is really meant to be random with equal probability for each possible values.

Input Format

The first line of input will contain three integers **N, K, Q**: **1 , the number of nodes of tomel tree, the universe of flavors and the number of Ada's questions.** The next line will contain **N-1** integers **0 is the parent of **i $ ^{th} $** node (here **i** goes from **1** to **N-1**).** The next line will contain **N** integers **1 , the flavor of each fruit.** The next **Q** lines will contain six integers **0 , where the pairs of beginings/ends of the paths are: (**B, E**), (**X, Y**), (**L, R**)**

Output Format

For each query output the number of distinct flavors which are on the three paths.