#429. I love max and multiply

I love max and multiply

Description

Mr.I has two sequence AiA_i and BiB_i of length n,(0⩽i⩽n−1)(0 \leqslant i \leqslant n−1).

Define an array C of length n, where Ck=max{AiBj}C_k={max}\{A_iB_j\}, satisfying (i&j⩾k)(i\&j \geqslant k).

& is the button under binary Bitwise AND operation.

Please calculate the value of ∑i=0n−1Ci\sum_{i=0}^{n-1} C_i, modulo 998244353.

Format

Input

The first line contains an integer T . Then T test cases follow.

Each test case contains three lines.

The first one contains an integer n(1≤n≤218)n(1≤n≤2^{18}) — length of the array a.

The second one contains n integers A0,A1,A2,...,An−1(∣Ai∣≤109)A_0,A_1,A_2,...,A_{n−1}(|A_i|≤10^9)

The third one contains n integers B0,B1,B2,...,Bn−1(∣Bi∣≤109)B_0,B_1,B_2,...,B_{n−1}(|B_i|≤10^9)

∑n≤219

Output

For each test case, output a single integer ans,where ans=∑i=0n−1Cians=\sum_{i=0}^{n-1} C_i modulo 998244353.

Samples

1
4
9 1 4 1
5 4 1 1
54