Pizza Delivery

No attempts yetTime limit1sMemory limit128 MB

Problem

A pizza house stands at a fixed point on a straight road, and many customer houses lie along that same road. To attract more orders, the owner promises a late-delivery discount: once a fixed grace period has passed after an order is placed, a penalty of 1 won accrues for every unit of time until the pizza is handed over.

Today every house ordered at the same moment, and delivery begins exactly when the grace period ends, so the penalty starts counting from time 00. The owner drives at a speed of one unit of distance per unit of time, and handing a pizza to a customer takes no time.

The profit from serving a customer equals that customer's earning minus the accumulated late penalty, and that penalty equals the time at which the pizza reaches them. On a busy day the owner may skip a customer whenever the penalty would exceed the earning, since serving them would lose money. Decide which customers to serve, and in what order, so that the total profit is as large as possible.

For example, the figure below shows five customers c1,,c5c_1, \ldots, c_5, their positions relative to the pizza house, and the earning from each.

If the delivery order is c4,c3,c2,c5,c1\langle c_4, c_3, c_2, c_5, c_1 \rangle, the late penalties are 22 for c4c_4, 55 for c3c_3, 77 for c2c_2, 1515 for c5c_5, and 2626 for c1c_1, so the per-customer profits are 3,3,3,5,13, -3, 3, 5, 1. Because serving c3c_3 loses 33, it is better to skip c3c_3, and this order yields a total profit of 1212. The best the owner can do for this instance is 3232, achieved by the order c3,c2,c1,c5\langle c_3, c_2, c_1, c_5 \rangle (skipping c4c_4).

Given the customers' positions relative to the pizza house and the earning from each, compute the maximum total profit.

Input

The first line contains the number of test cases TT. Each test case is given on three lines.

  • The first line contains an integer nn (1n1001 \le n \le 100), the number of customers.
  • The second line contains nn integers p1<p2<<pnp_1 < p_2 < \cdots < p_n (each pi0p_i \ne 0), where pip_i is the position of the ii-th customer relative to the pizza house.
  • The third line contains nn integers e1,e2,,ene_1, e_2, \ldots, e_n (each ei>0e_i > 0), where eie_i is the earning from serving customer ii.

Every integer on the second and third lines lies between 100000-100000 and 100000100000 inclusive.

Output

For each test case, print a single line containing the maximum total profit obtainable by delivering pizzas to the customers.