You are given a tree with N vertices. The distance between two vertices is the number of edges lying on the simple path between them.
There are Q queries. Each query is specified by two vertices u and v and an integer d. A pair of vertices is called good if the distance between them is not less than d. In each step, you can only move between a good pair of vertices. Now your task is to calculate the minimum number of steps you have to make in order to get from u to v. If you can not reach the destination, the answer is −1.
A lot of queries are given to you to make this problem difficult.
The first line of input contains three integers N, Q and M: the number of vertices, the number of queries and the upper bound for d. (1≤N≤2⋅105, 1≤Q≤106, 1≤M≤2⋅105).
The second line contains N−1 integers f_2, f_3, …, f_N which mean that, for every i such that 2≤i≤N, there is an edge between vertices i and f_i in the tree (1≤f_i<i).
The third line contains six integers u_1, v_1, d_1, A, B and C (1≤u_1,v_1≤N, 0≤d_1<M, 104≤A,B,C≤2⋅104).
The first query is specified by u_1, v_1 and d_1.
The i-th (2≤i≤Q) query is specified by u_i, v_i and d_i which are generated by the following rules:
Here, ans_k is the answer for query k.
Output the integer S=∑_i=1Qi⋅(ans_i+1).