Parents

No attempts yetTime limit5sMemory limit128 MB

Problem

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 KK, a KK-anti-parental subset is a set of nodes that satisfies both of the following:

  1. it contains between 11 and KK nodes, inclusive;
  2. no node in the set is the parent of another node in the set (equivalently, the set contains no parent-child pair).

Given a node-valued tree and KK, compute the maximum possible value of a KK-anti-parental subset.

Input

The first line contains the number of test cases TT. Each test case is given as follows.

The first line of a test case contains two integers NN and KK: the number of nodes and the parameter KK, with N100000N \le 100000 and 1K1001 \le K \le 100. Nodes are indexed from 00 to N1N-1, and node 00 is always the root.

The second line contains NN integers, the values of nodes 00 through N1N-1 in order, each in the range [1000,1000][-1000, 1000].

The third line contains N1N-1 integers: the parent index of each node from 11 to N1N-1, in increasing order of index. The first of these integers is the parent of node 11. The root (node 00) has no parent entry. When N=1N = 1 this line is empty.

Output

For each test case, print a single line containing the maximum possible value of a KK-anti-parental subset of that tree.