Under construction

Still being built. Things may change

Quantum Moochanics

Time limit2sMemory limit1024 MB

Summary
Given alternating mootrinos and antimootrinos on a line that reverse direction at each observation, find the observation number when each particle disappears.
Level

Medium7 of 10

Topics
Simulation, Binary search, Math
Solved
No attempts yet

Problem

In her free time, Bessie likes to dabble in experimental physics. She recently discovered a pair of new subatomic particles, mootrinos and antimootrinos. Like ordinary matter-antimatter pairs, a mootrino and an antimootrino annihilate each other and disappear when they meet. What makes these particles unusual is that each one reverses its direction of motion, keeping the same speed, whenever Bessie looks at them.

For her latest experiment, Bessie has placed an even number NN (2≤N≤2⋅1052 \le N \le 2 \cdot 10^5) of these particles in a line. The line starts with a mootrino on the left and then alternates between the two types of particles. The ii-th particle is at position pip_i (0≤p1⋯<pN≤10180 \le p_1 \cdots < p_N \le 10^{18}). Mootrinos initially move right, and antimootrinos initially move left. The ii-th particle moves at a constant speed of sis_i units per second (1≤si≤1091 \le s_i \le 10^9).

Bessie makes observations at the following times. The first observation is 1 second after the start of the experiment. Each later observation comes 2 seconds after the previous one, then 3 seconds after that, and so on. In general, the (n+1)(n+1)-th observation comes n+1n+1 seconds after the nn-th observation. During each observation, Bessie notes which particles have disappeared.

The experiment may take an extremely long time, so Bessie wants to simulate its results first. Given the setup, determine the observation number at which Bessie sees each particle disappear. It may be shown that all particles eventually disappear.

Input

Each input contains TT (1≤T≤101 \le T \le 10) independent test cases.

Each test case consists of three lines. The first line contains NN. The second line contains p1,…,pNp_1, \dots, p_N. The third line contains s1,…,sNs_1, \dots, s_N.

The sum of all NN does not exceed 2⋅1052 \cdot 10^5.

Output

For each test case, output the observation number for each particle's disappearance, separated by spaces.

Examples2

  1. Example 1

    Input
    4
    2
    1 11
    1 1
    2
    1 12
    1 1
    2
    1 11
    4 6
    2
    1 11
    4 5
    
    Expected output
    9 9
    11 11
    1 1
    3 3
    
  2. Example 2

    Input
    2
    4
    1 3 5 8
    1 1 1 1
    4
    1 4 5 8
    1 1 1 1
    
    Expected output
    1 1 3 3
    7 2 2 7