Under construction

Still being built. Things may change

Osmanthus Tree

Time limit0.5sMemory limit1024 MB

Summary
Count trees on n+m vertices that keep the LCAs of the given tree T on vertices 1 to n and keep each pairwise LCA label within max(i, j) + k, modulo 1e9+7.
Level

Hard9 of 10

Topics
Dynamic programming, Tree, Combinatorics
Solved
No attempts yet

Problem

Eight years ago, Little B saw an osmanthus tree, which is a tree TT with nn vertices, where the parent vertex of any non-root vertex in TT has a smaller label than its own. Given an integer kk, a rooted tree T′T' with (n+m)(n + m) vertices is prosperous if and only if the following conditions are met:

  • For any (i,j)(i, j) with 1≤i,j≤n1 \leq i, j \leq n, the lowest common ancestor of vertices ii and jj in TT and T′T' has the same label.
  • For any (i,j)(i, j) with 1≤i,j≤n+m1 \leq i, j \leq n + m, the label of the lowest common ancestor of vertices ii and jj in T′T' does not exceed max⁡(i,j)+k\max(i, j) + k.

All vertices are labeled starting from 11, and the root has label 11. T′T' does not need to satisfy the condition that the parent vertex of any non-root vertex has a smaller label than its own.

Little B wants to know how many trees with (n+m)(n + m) vertices are prosperous. Two trees are different if there is a vertex whose parent differs between the two trees. Output the count modulo 109+710^9+7.

Input

The input contains multiple test data sets.

The first line contains two integers cc and tt, where cc is the test case number and tt is the number of test data sets. If c=0c = 0, this is a sample test.

Each test data set starts with a line containing three integers nn, mm, and kk. The next line contains n−1n - 1 integers f2,f3,…,fnf_2, f_3, \ldots, f_n, where fif_i is the label of the parent vertex of vertex ii in TT.

Output

For each test data set, output one line containing the number of prosperous trees modulo 109+710^9+7.

Constraints

For all test data, it is guaranteed that:

  • 1≤t≤151 \leq t \leq 15
  • 1≤n≤3×1041 \leq n \leq 3 \times 10^4
  • 0≤m≤30000 \leq m \leq 3000
  • 0≤k≤100 \leq k \leq 10
  • 1≤fi≤i−11 \leq f_i \leq i - 1

Examples1

  1. Example 1

    Input
    0 3
    1 2 1
    2 2 1
    1
    2 2 0
    1
    
    Expected output
    3
    16
    15