Under construction

Still being built. Things may change

Counting Is Not Fun (Hard Version)

Time limit3sMemory limit2048 MB

Summary
Given n clues that each force a good pair in a balanced bracket sequence with n pairs, count the matching sequences before and after each clue, modulo 998244353.
Level

Hard8 of 10

Topics
Combinatorics, Math, Implementation
Solved
No attempts yet

Problem

This is the hard version of the problem. The two versions differ in that this version has larger limits on tt and nn. You can hack only if you solved all versions of this problem.

Now Little John is rich, so he finally buys a house big enough to fit himself and his favorite bracket sequence. But somehow he ended up with a lot of brackets! Frustrated, he penetrates through the ceiling with the "buddha palm".

A bracket sequence is called balanced if it can be constructed by the following formal grammar.

  1. The empty sequence ∅\varnothing is balanced.
  2. If the bracket sequence AA is balanced, then (A)\mathtt{(}A\mathtt{)} is also balanced.
  3. If the bracket sequences AA and BB are balanced, then the concatenated sequence ABAB is also balanced.

For example, the sequences "(())()", "()", "(()(()))", and the empty sequence are balanced, while "(()" and "(()))(" are not.

Given a balanced bracket sequence ss, a pair of indices (i,j)(i,j) (i<ji<j) is called a good pair if sis_i is '(', sjs_j is ')', and the two brackets are added simultaneously with respect to Rule 2 while constructing the sequence ss. For example, the sequence "(())()" has three different good pairs, which are (1,4)(1,4), (2,3)(2,3), and (5,6)(5,6). One can show that any balanced bracket sequence of 2n2n brackets contains exactly nn different good pairs, and using any order of rules to construct the same bracket sequence will yield the same set of good pairs.

Emily will play a bracket guessing game with John. The game is played as follows.

Initially, John has a balanced bracket sequence ss containing nn different good pairs, which is not known to Emily. John tells Emily the value of nn and asks Emily to guess the sequence.

Throughout nn turns, John gives Emily the following kind of clue on each turn.

  • l rl\,r: The sequence ss contains a good pair (l,r)(l,r).

The clues that John gives Emily are pairwise distinct and do not contradict each other.

At a certain point, Emily can be certain that the balanced bracket sequence satisfying the clues given so far is unique. For example, assume Emily knows that ss has 33 good pairs, and it contains the good pair (2,5)(2,5). Out of 55 balanced bracket sequences with 33 good pairs, there exists only one such sequence "((()))" with the good pair (2,5)(2,5). Therefore, one can see that Emily does not always need nn turns to guess ss.

To find out the content of ss as early as possible, Emily wants to know the number of different balanced bracket sequences that match the clues after each turn. This is not an easy job for Emily, especially when she is given so many good pairs. Now it is your turn to help Emily. Given the clues, you must find the answer before and after each turn. As the answers may be huge, you need to find them modulo 998 244 353998\,244\,353.

Input

The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains one integer nn (2≤n≤3⋅1052 \le n \le 3 \cdot 10^5), the number of good pairs.

Then, each of the nn following lines contains two integers lil_i and rir_i representing the ii-th clue (1≤li<ri≤2n1 \le l_i < r_i \le 2n).

The clues in one test case are pairwise distinct and do not contradict each other.

It is guaranteed that the sum of nn over all test cases does not exceed 3⋅1053 \cdot 10^5.

Output

For each test case, output n+1n+1 integers on a separate line:

  • The first integer is the answer before all clues, modulo 998 244 353998\,244\,353.
  • For all i≥1i \ge 1, the i+1i+1-th integer is the answer after the ii-th clue, modulo 998 244 353998\,244\,353.

Hint

The first test case of the example is explained in the problem description.

The third test case of the example is explained as follows. It can be shown that there are 132132 balanced bracket sequences with 66 good pairs. The answers after each clue are given as follows:

  1. You are given the good pair (2,3)(2,3). There are 4242 balanced bracket sequences having the good pair (2,3)(2,3).
  2. You are given the good pair (1,6)(1,6). There are 55 balanced bracket sequences having the good pairs (2,3)(2,3) and (1,6)(1,6).
  3. You are given the good pair (7,8)(7,8). There are 22 balanced bracket sequences having all three good pairs. The strings are "(()())()(())" and "(()())()()()", respectively.
  4. You are given the good pair (9,12)(9,12). There is only one balanced bracket sequence having the four good pairs. The content of ss is therefore the only string, which is "(()())()(())".

Examples1

  1. Example 1

    Input
    3
    3
    2 5
    1 6
    3 4
    4
    1 6
    7 8
    2 3
    4 5
    6
    2 3
    1 6
    7 8
    9 12
    10 11
    4 5
    
    Expected output
    5 1 1 1
    14 2 2 1 1
    132 42 5 2 1 1 1