There are cities numbered from to in a country. Two consecutive cities are connected by a bidirectional road (City is connected with city for each ). There lives exactly one hero in each city. There are types of heroes. The hero of the -th city has a type .
Each hero has a power denoted by an integer number which can increase or decrease based on their activity. Initially, the hero of the -th city has power . The heroes can move from one city to another by using the roads. When a hero moves from city to , or from city to , the power of the hero decreases by . The powers can not be negative. When the power is , the hero can still move but the power does not decrease (in this case, he is inactive). Initially, each of the roads contains an energy drink. While passing through a road, a hero can pick the energy drink and drink it, increasing his power by . An energy drink can be used exactly once.
You want to gather heroes in one city. You have to invite exactly one hero from each of the types of heroes. You want to choose the city and heroes in such a way that after gathering in that city, the sum of powers of the heroes you invited is maximum possible.
What is the maximum power you can achieve?
The first line of input contains an integer the number of test cases.
The first line of each test case contains two integers and denoting the number of cities and the number of types of heroes.
The next line contains integers type of each hero.
The next line contains integers initial power of each hero.
It is guaranteed that there exists at least one hero of each type in the input.
The sum of over all the test cases does not exceed .
For each test case, print one integer the maximum possible power of the gathered heroes.
Input | Output |
---|---|
2 5 3 1 3 1 2 3 4 1 1 3 2 5 4 3 2 2 1 4 3 1 2 6 6 | 9 16 |
In the first test case, you can invite the heroes of the st, th and th cities at city . The power of the st hero will decrease by . But he can drink energy drinks kept on the streets between the city , and . The hero of the th city will not lose any power. The power of the hero of the th city will decrease but it will be restored after drinking the energy drink on the road between city and . The total power is . In the second test case, you can invite the heroes of the st, rd, th and th cities at city . The hero of the st city can drink the energy drink between the city and , and leave the energy drink between the city for the hero of the rd city. Thus he can reach city with power . The hero of the rd city can drink the energy drink between the city and reach city without losing any power. The hero of the th city can drink the energy drink between the city and reach city with power . The total power will be . |