CF2173B.Niko's Tactical Cards

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Niko's Tactical Cards

Niko is playing a game. Her score is denoted by an integer kk which is 00 initially.

The game has nn turns. On the ii-th turn, Niko is given a red card with an integer aia_i on it, as well as a blue card with an integer bib_i on it. She must choose exactly one of the cards and update her score according to her choice:

  • If she chooses the red card, her score becomes kaik - a_i, where kk is her score before the turn.
  • If she chooses the blue card, her score becomes bikb_i - k, where kk is her score before the turn.

After this, the game proceeds to the next turn, or ends if it is the nn-th turn.

Your task is to find the maximum possible score Niko can obtain at the end of the game.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1031 \le t \le 10^3). The description of the test cases follows.

The first line of each test case contains a single integer nn (1n1051 \le n \le 10^5) — the number of turns.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (109ai109-10^9 \le a_i \le 10^9).

The third line of each test case contains nn integers b1,b2,,bnb_1, b_2, \ldots, b_n (109bi109-10^9 \le b_i \le 10^9).

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

Output

For each test case, output a single integer — the maximum possible score Niko can obtain at the end of the game.

Note

In the first test case, one optimal strategy is as follows:

Turn 0 1 2 3
Card Chosen Blue Red
Score 00 30=3-3 - 0 = -3 3(8)=5-3 - (-8) = 5 5(1)=65 - (-1) = 6

In the second test case, one optimal strategy is as follows:

Turn 0 1 2 3 4 5
Card Chosen Blue Red
Score 00 5-5 88 9-9 1313 1212

Samples

3
3
4 -8 -1
-3 -7 0
5
-3 1 0 7 1
-5 3 -1 4 -5
5
-7 7 5 4 9
-9 -3 3 2 2
6
12
27

在线编程 IDE

建议全屏模式获得最佳体验