You live in a city that consists of N restaurants. Each restaurant has a unique index between 1 and N (both inclusive) and value denoted by the array V . A unique path exists between every pair of restaurants, which implies that each restaurant can be reached from every other restaurant. You are given an integer P. Your task is to solve Q queries of the following form:
A B L1 R1 L2 R2
where A and B are the indices of two distinct restaurants and L1, R1, L2, and R2 are positive integers. For each query, determine the total number of ordered pairs of restaurants (X,Y) such that the following conditions hold:
X lies in the unique path between the restaurants A and B
A lies in the unique path between the restaurants X and Y
L1≤(VX%P)≤R1
L2≤(VY%P)≤R2
A, B, X, and Y should be pairwise distinct
Input format
where ⊕ is the symbol for the bitwise XOR.
Output format
For each query, print the answer on a separate line.
Constraints
2≤N,Q≤105
1≤A,B≤N and A≠B
1≤L1,R1,L2,R2,P,Vi≤109
L1≤R1 and L2≤R2
Subtasks
11 5 20 10 5 6 10 10 10 10 10 10 10 10 1 2 1 3 2 4 2 5 4 6 4 7 5 8 3 9 9 10 9 11 4 9 1 20 1 20 2 13 7 18 7 18 12 3 9 1 9 1 4 2 1 10 1 10 4 1 1 10 1 10
For the first query the possible pairs satisfying all the conditions are (1,6), (2,6), (3,6), (1,7), (2,7) and (3,7).