1670 - The traffic condition

Time Limit : 5 Second

Memory Limit : 512 MB

Submission: 10

Solved: 4

Description

Minieye is a company that applying technology of computer vision on Advanced Driver Assistance Systems (ADAS). Not surprisingly, they are very concerned about the situation of urban traffic. We simplify the city's roads and intersections as edges and vertices and regard the whole city as a tree.We number the intersections from 1 to N and give every intersection a value to represent its congestion.Now give you, the algorithm engineer in Minieye, a number K, you should calculate the maximum total value of a connected block that includes K intersections.

Input

There are T test cases, the first line is T, each case contains a number of lines. For each case, the first line is N and K, the second line contains N numbers that are value of N nodes, and the third line contains N-1 numbers that are the fathers of the node from 2 to N, because the first node is the root of this tree.


Notes:


1 <= K <= 100


1 <= N <= 1000


1 <= value of node <= 1000


K <= N


 

Output

For each test case, output one line containing the maximum total value.

sample input
2
3 2
10 10 10
1 1
5 3
1 2 3 4 5
1 2 3 4
sample output
20
12
hint
source
© 2015 HUST ACMICPC TEAM. All Right Reserved.