Minimum Scalar Product (Small)

Permute two vectors to minimize their dot product and print the minimum.

Medium4SortingGreedyMathInterviewNo attempts yetTime limit5sMemory limit512 MB

Problem

You are given two vectors v1=(x1,x2,,xn)v_1 = (x_1, x_2, \dots, x_n) and v2=(y1,y2,,yn)v_2 = (y_1, y_2, \dots, y_n). The scalar product of the two vectors is a single number, computed as x1y1+x2y2++xnynx_1 y_1 + x_2 y_2 + \dots + x_n y_n.

You may permute the coordinates of each vector however you like. Choose two permutations that make the scalar product of the resulting vectors as small as possible, then print that minimum scalar product.

Input

The first line contains the number of test cases TT. For each test case, the first line contains an integer nn, and the next two lines contain nn integers each, giving the coordinates of v1v_1 and v2v_2 in order.

Limits

  • 1T10001 \le T \le 1000
  • 1n81 \le n \le 8
  • 1000xi,yi1000-1000 \le x_i, y_i \le 1000

Output

For each test case, print one line

Case #X: Y

where XX is the test case number starting from 1, and YY is the minimum scalar product over all permutations of the two given vectors.