Dome Stadium

No attempts yetTime limit1sMemory limit256 MB

Problem

A baseball team is planning to build a domed stadium. The city is laid out as NN villages in a straight line along a single highway, and each village sits at a distinct integer coordinate on the x-axis. From a survey, the team already knows how many baseball fans live in each village.

The team wants to place the stadium in one of the villages so that the total travel distance from every fan to the stadium is as small as possible. A village that holds ff fans and sits at distance dd from the stadium contributes f×df \times d to this total. In other words, if a village's coordinate is xix_i and the chosen stadium coordinate is pp, the total distance is the sum of fi×xipf_i \times |x_i - p| over all villages.

For example, suppose there are 5 villages at coordinates (1,2,5,7,8)(1, 2, 5, 7, 8) with fan counts (3,2,4,3,1)(3, 2, 4, 3, 1). Building the stadium in the village at x-coordinate 55 minimizes the total distance from all fans.

Write a program that finds the village coordinate that minimizes the total distance from every fan to the stadium. The stadium must be built in one of the villages, and every village lies on an integer x-coordinate.

Input

The input is read from standard input. The first line contains an integer TT, the number of test cases. Each test case is given on three lines.

  • The first line contains an integer NN (1<N1000001 < N \le 100000), the number of villages.
  • The second line contains NN integers, the village coordinates on the x-axis in ascending order. Each coordinate is between 11 and 100000000100000000.
  • The third line contains NN positive integers, the number of fans in each village. Each count is between 11 and 1000010000.

Output

Write to standard output. For each test case, print exactly one line containing a single integer: the coordinate of the village that minimizes the total distance from all fans to the stadium. If several villages achieve the same minimum, print the smallest such coordinate.