You are given a rooted tree whose nodes each carry an integer value. The value of a set of nodes is the sum of the values of the nodes it contains.
For a positive integer K, a K-anti-parental subset is a set of nodes that satisfies both of the following:
Given a node-valued tree and K, compute the maximum possible value of a K-anti-parental subset.
The first line contains the number of test cases T. Each test case is given as follows.
The first line of a test case contains two integers N and K: the number of nodes and the parameter K, with N≤100000 and 1≤K≤100. Nodes are indexed from 0 to N−1, and node 0 is always the root.
The second line contains N integers, the values of nodes 0 through N−1 in order, each in the range [−1000,1000].
The third line contains N−1 integers: the parent index of each node from 1 to N−1, in increasing order of index. The first of these integers is the parent of node 1. The root (node 0) has no parent entry. When N=1 this line is empty.
For each test case, print a single line containing the maximum possible value of a K-anti-parental subset of that tree.