Under construction

Still being built. Things may change

Dice Game

Time limit5sMemory limit1024 MB

Summary
Given a die with n faces, find the expected score of a game where Budada either keeps the first roll or XORs it with a second roll, both playing optimally, modulo 998244353.
Level

Medium7 of 10

Topics
Probability, Bit manipulation, Math
Solved
No attempts yet

Problem

Putata and Budada are playing a game with a die that has nn faces. Every integer from 00 to n−1n-1 is written on exactly one face, and each face is equally likely to land up. In other words, a roll gives a uniform random integer between 00 and n−1n-1.

The game has two rounds. In the first round, Putata rolls the die and gets an integer xx.

In the second round, Budada can choose one of the following:

  • End the game. The score is xx.
  • Roll the die again and let the result be yy. The game ends, and the score is x⊕yx \oplus y, where ⊕\oplus is the bitwise exclusive-or operation.

Putata and Budada want to maximize the score, and both always make the best choice. For a given nn, compute the expected score of the game.

The answer can be written as an irreducible fraction xy\frac{x}{y} with y≢0(mod998 244 353)y \not\equiv 0 \pmod{998\,244\,353}. Output the integer aa with 0≤a<998 244 3530 \leq a < 998\,244\,353 and a⋅y≡x(mod998 244 353)a \cdot y \equiv x \pmod{998\,244\,353}.

Input

The first line contains an integer TT (1≤T≤1041 \leq T \leq 10^4). Each of the next TT lines contains an integer nn (1≤n≤998 244 3521 \leq n \leq 998\,244\,352), which is one query.

Output

Output TT lines. Line ii contains the answer for the ii-th query.

Examples1

  1. Example 1

    Input
    4
    1
    2
    3
    4
    
    Expected output
    0
    249561089
    776412276
    2