Under construction

Still being built. Things may change

XOR Determinant

Time limit1sMemory limit1024 MB

Summary
Given arrays b and c, find the determinant mod 998244353 of the n by n matrix whose entries are b_i XOR c_j.
Level

Medium7 of 10

Topics
Math, Matrix, Bit manipulation
Solved
No attempts yet

Statement

You are given two arrays bb and cc of length nn, each containing non-negative integers. Build the n×nn \times n matrix AA with Aij=bi⊕cjA_{ij} = b_i \oplus c_j. Find the determinant of AA modulo 998244353998244353.

Input

Each test contains multiple test cases. The first line contains an integer tt (1≤t≤10001 \le t \le 1000), the number of test cases. Each test case starts with a line containing nn (1≤n≤50001 \le n \le 5000). The next line contains b1,b2,…,bnb_1, b_2, \ldots, b_n (0≤bi<2600 \le b_i < 2^{60}), and the line after that contains c1,c2,…,cnc_1, c_2, \ldots, c_n (0≤ci<2600 \le c_i < 2^{60}). The sum of nn over all test cases does not exceed 1000010000.

Output

For each test case, print the determinant of AA modulo 998244353998244353 on its own line.

Hint

First test case: ∣6314∣=6⋅4−1⋅3=21\begin{vmatrix} 6 & 3 \\ 1 & 4 \end{vmatrix} = 6 \cdot 4 - 1 \cdot 3 = 21. Second test case: the matrix is 1×11 \times 1, so ∣23792195055071677∣=23792195055071677\begin{vmatrix} 23792195055071677 \end{vmatrix} = 23792195055071677. Modulo 998244353998244353, this is 214139910214139910. Third test case: ∣0325301621075670∣\begin{vmatrix} 0 & 3 & 2 & 5 \\ 3 & 0 & 1 & 6 \\ 2 & 1 & 0 & 7 \\ 5 & 6 & 7 & 0 \end{vmatrix} expands to 3⋅3⋅7⋅7−3⋅1⋅7⋅5−3⋅6⋅2⋅7−2⋅3⋅7⋅6+2⋅6⋅2⋅6−2⋅6⋅1⋅5−5⋅3⋅1⋅7−5⋅1⋅2⋅6+5⋅1⋅1⋅5=441−105−252−252+144−60−105−60+25=−2243 \cdot 3 \cdot 7 \cdot 7 - 3 \cdot 1 \cdot 7 \cdot 5 - 3 \cdot 6 \cdot 2 \cdot 7 - 2 \cdot 3 \cdot 7 \cdot 6 + 2 \cdot 6 \cdot 2 \cdot 6 - 2 \cdot 6 \cdot 1 \cdot 5 - 5 \cdot 3 \cdot 1 \cdot 7 - 5 \cdot 1 \cdot 2 \cdot 6 + 5 \cdot 1 \cdot 1 \cdot 5 = 441 - 105 - 252 - 252 + 144 - 60 - 105 - 60 + 25 = -224 Modulo 998244353998244353, −224-224 becomes 998244129998244129.

Examples1

  1. Example 1

    Input
    3
    2
    2 5
    4 1
    1
    1000000000000000001
    987467354324283836
    4
    1 2 3 4
    1 2 3 4
    
    Expected output
    21
    214139910
    998244129