You are given a rooted tree with n vertices. Assign the numbers 1 through n to the vertices, using each number exactly once, so that every vertex receives a number smaller than its parent's number. In other words, the root holds the largest number and the numbers decrease from parents to children, forming a max-heap.
Count the number of such labelings. Since this number can be very large, print it modulo m.
The first line contains the number of test cases t. (1≤t≤250)
The first line of each test case contains the number of vertices n and the modulus m. (1≤n≤500,000, 2≤m≤109)
The i-th of the next n−1 lines contains pi+1, the parent of vertex i+1. (1≤pi+1≤i) Vertex 1 is always the root. The total input size does not exceed 50MB.
For each test case, print the number of valid labelings modulo m, one per line.
For example, in the last case of the sample (n=5, where vertices 2,3,4,5 have parents 1,1,3,3), there are exactly 8 valid labelings.
Note that m is not necessarily prime, so you cannot directly divide (use a modular inverse) under the modulus.