#P1879F. Last Man Standing

    ID: 8710 Type: RemoteJudge 7000ms 512MiB Tried: 0 Accepted: 0 Difficulty: 10 Uploaded By: Tags>brute forcedata structuresnumber theory*2800

Last Man Standing

No submission language available for this problem.

Description

There are nn heroes in a videogame. Each hero has some health value hh and initial armor value aa. Let the current value of armor be acura_{\mathit{cur}}, initially equal to aa.

When xx points of damage are inflicted on a hero, the following happens: if x<acurx < a_{\mathit{cur}}, then xx gets subtracted from acura_{\mathit{cur}}; otherwise, 11 gets subtracted from hh and acura_{\mathit{cur}} gets assigned back to aa.

In the start of the game, you choose the value xx (an integer strictly greater than 00, arbitrarily large). Then you keep attacking all heroes in rounds: in one round, you inflict xx points of damage to all alive heroes. A hero dies when his health becomes 00. The game ends when all heroes are dead.

The last hero to die earns the number of points, equal to the number of rounds he was the only hero alive. The other heroes get 00 points. In particular, if the last round ends with multiple heroes dying, then every hero gets 00 points.

The game is played for every possible xx (from 11 to infinity). The points are reset between the games. What's the maximum number of points each hero has had?

The first line contains a single integer tt (1t101 \le t \le 10) — the number of testcases.

The first line of each testcase contains a single integer nn (1n21051 \le n \le 2 \cdot 10^5) — the number of heroes.

The second line contains nn integers h1,h2,,hnh_1, h_2, \dots, h_n (1hi21051 \le h_i \le 2 \cdot 10^5) — the health value of each hero.

The third line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ai21051 \le a_i \le 2 \cdot 10^5) — the initial armor value of each hero.

For each testcase, print nn integers — the maximum number of points each hero has had over the games played for every possible xx.

Input

The first line contains a single integer tt (1t101 \le t \le 10) — the number of testcases.

The first line of each testcase contains a single integer nn (1n21051 \le n \le 2 \cdot 10^5) — the number of heroes.

The second line contains nn integers h1,h2,,hnh_1, h_2, \dots, h_n (1hi21051 \le h_i \le 2 \cdot 10^5) — the health value of each hero.

The third line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ai21051 \le a_i \le 2 \cdot 10^5) — the initial armor value of each hero.

Output

For each testcase, print nn integers — the maximum number of points each hero has had over the games played for every possible xx.

Sample Input 1

3
3
3 1 2
3 11 5
1
100
200
4
5 9 5 1
9 2 9 10

Sample Output 1

1 1 1 
20000 
0 4 0 0

Note

In the first testcase, the game for x=1x = 1 is played as follows:

  • before all rounds: the heroes have h=[3,1,2]h = [3, 1, 2], acur=[3,11,5]a_{\mathit{cur}} = [3, 11, 5];
  • round 11: 11 damage is inflicted on every hero: hh remains [3,1,2][3, 1, 2], acura_{\mathit{cur}} becomes [2,10,4][2, 10, 4];
  • round 22: h=[3,1,2]h = [3, 1, 2], acur=[1,9,3]a_{\mathit{cur}} = [1, 9, 3];
  • round 33: the first hero runs out of armor, so he loses a health point: h=[2,1,2]h = [2, 1, 2], acur=[3,8,2]a_{\mathit{cur}} = [3, 8, 2];
  • ...
  • round 99: the first hero dies, since his health reaches 00: h=[0,1,1]h = [0, 1, 1], acur=[0,2,1]a_{\mathit{cur}} = [0, 2, 1];
  • round 1010: the third hero dies: h=[0,1,0]h = [0, 1, 0], acur=[0,1,0]a_{\mathit{cur}} = [0, 1, 0];
  • round 1111: the second hero dies: h=[0,0,0]h = [0, 0, 0], acur=[0,0,0]a_{\mathit{cur}} = [0, 0, 0].

The second hero was the last hero to die, and he was the only hero alive during one round. Thus, he gets 11 point for that game.

The game for x=4x = 4 is played as follows:

  • round 11: h=[2,1,2]h = [2, 1, 2], acur=[3,7,1]a_{\mathit{cur}} = [3, 7, 1];
  • round 22: h=[1,1,1]h = [1, 1, 1], acur=[3,3,5]a_{\mathit{cur}} = [3, 3, 5];
  • round 33: h=[0,0,1]h = [0, 0, 1], acur=[0,0,1]a_{\mathit{cur}} = [0, 0, 1];
  • round 44: h=[0,0,0]h = [0, 0, 0], acur=[0,0,0]a_{\mathit{cur}} = [0, 0, 0];

The third hero was the last hero to die, and he was the only hero alive during one round.