#P1721C. Min-Max Array Transformation

    ID: 856 Type: RemoteJudge 2000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 4 Uploaded By: Tags>binary searchgreedytwo pointers*1400

Min-Max Array Transformation

Description

You are given an array a1,a2,,ana_1, a_2, \dots, a_n, which is sorted in non-descending order. You decided to perform the following steps to create array b1,b2,,bnb_1, b_2, \dots, b_n:

  1. Create an array dd consisting of nn arbitrary non-negative integers.
  2. Set bi=ai+dib_i = a_i + d_i for each bib_i.
  3. Sort the array bb in non-descending order.

You are given the resulting array bb. For each index ii, calculate what is the minimum and maximum possible value of did_i you can choose in order to get the given array bb.

Note that the minimum (maximum) did_i-s are independent of each other, i. e. they can be obtained from different possible arrays dd.

The first line contains the single integer tt (1t1041 \le t \le 10^4) — the number of test cases.

The first line of each test case contains a single integer nn (1n21051 \le n \le 2 \cdot 10^5) — the length of arrays aa, bb and dd.

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ai1091 \le a_i \le 10^9; aiai+1a_i \le a_{i+1}) — the array aa in non-descending order.

The third line contains nn integers b1,b2,,bnb_1, b_2, \dots, b_n (1bi1091 \le b_i \le 10^9; bibi+1b_i \le b_{i+1}) — the array bb in non-descending order.

Additional constraints on the input:

  • there is at least one way to obtain the array bb from the aa by choosing an array dd consisting of non-negative integers;
  • the sum of nn doesn't exceed 21052 \cdot 10^5.

For each test case, print two lines. In the first line, print nn integers d1min,d2min,,dnmind_1^{min}, d_2^{min}, \dots, d_n^{min}, where dimind_i^{min} is the minimum possible value you can add to aia_i.

Secondly, print nn integers d1max,d2max,,dnmaxd_1^{max}, d_2^{max}, \dots, d_n^{max}, where dimaxd_i^{max} is the maximum possible value you can add to aia_i.

All dimind_i^{min} and dimaxd_i^{max} values are independent of each other. In other words, for each ii, dimind_i^{min} is just the minimum value among all possible values of did_i.

Input

The first line contains the single integer tt (1t1041 \le t \le 10^4) — the number of test cases.

The first line of each test case contains a single integer nn (1n21051 \le n \le 2 \cdot 10^5) — the length of arrays aa, bb and dd.

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ai1091 \le a_i \le 10^9; aiai+1a_i \le a_{i+1}) — the array aa in non-descending order.

The third line contains nn integers b1,b2,,bnb_1, b_2, \dots, b_n (1bi1091 \le b_i \le 10^9; bibi+1b_i \le b_{i+1}) — the array bb in non-descending order.

Additional constraints on the input:

  • there is at least one way to obtain the array bb from the aa by choosing an array dd consisting of non-negative integers;
  • the sum of nn doesn't exceed 21052 \cdot 10^5.

Output

For each test case, print two lines. In the first line, print nn integers d1min,d2min,,dnmind_1^{min}, d_2^{min}, \dots, d_n^{min}, where dimind_i^{min} is the minimum possible value you can add to aia_i.

Secondly, print nn integers d1max,d2max,,dnmaxd_1^{max}, d_2^{max}, \dots, d_n^{max}, where dimaxd_i^{max} is the maximum possible value you can add to aia_i.

All dimind_i^{min} and dimaxd_i^{max} values are independent of each other. In other words, for each ii, dimind_i^{min} is just the minimum value among all possible values of did_i.

Sample Input 1

4
3
2 3 5
7 11 13
1
1000
5000
4
1 2 3 4
1 2 3 4
4
10 20 30 40
22 33 33 55

Sample Output 1

5 4 2
11 10 8
4000
4000
0 0 0 0
0 0 0 0
12 2 3 15
23 13 3 15

Note

In the first test case, in order to get d1min=5d_1^{min} = 5, we can choose, for example, d=[5,10,6]d = [5, 10, 6]. Then bb == [2+5,3+10,5+6][2+5,3+10,5+6] == [7,13,11][7,13,11] == [7,11,13][7,11,13].

For d2min=4d_2^{min} = 4, we can choose dd == [9,4,8][9, 4, 8]. Then bb == [2+9,3+4,5+8][2+9,3+4,5+8] == [11,7,13][11,7,13] == [7,11,13][7,11,13].