Under construction

Still being built. Things may change

Counting Is Not Fun (Easy Version)

Time limit3sMemory limit2048 MB

Summary
After each clue fixing a good pair, count the balanced bracket sequences with n good pairs that contain all clues so far, modulo 998244353.
Level

Medium7 of 10

Topics
Dynamic programming, Combinatorics, String
Solved
No attempts yet

Statement

This is the easy version of the problem. The only difference is that this version has smaller 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 the ceiling with the "buddha palm".

A bracket sequence is called balanced if it can be constructed by the following 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 concatenation ABAB is also balanced.

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

Given a balanced bracket sequence ss, a pair of indices (i,j)(i,j) with i<ji<j is called a good pair if sis_i is (, sjs_j is ), and the two brackets were added together by Rule 2 while building ss. For example, "(())()" has three good pairs: (1,4)(1,4), (2,3)(2,3), and (5,6)(5,6). Every balanced bracket sequence of 2n2n brackets has exactly nn good pairs, and any order of applying the rules to build the same sequence gives the same set of good pairs.

Emily plays a bracket guessing game with John. John has a balanced bracket sequence ss with nn good pairs, and Emily does not know it. John tells Emily the value of nn and asks her to guess the sequence. Over nn turns, John gives one clue per turn:

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

The clues are pairwise distinct and do not contradict each other.

At some point Emily can be certain that only one balanced bracket sequence matches the clues so far. For example, suppose Emily knows ss has 33 good pairs and contains the good pair (2,5)(2,5). Of the 55 balanced bracket sequences with 33 good pairs, only "((()))" contains (2,5)(2,5), so Emily does not need all nn turns.

After each turn, Emily wants to know how many balanced bracket sequences match the clues so far. Counting these is hard when there are many good pairs. Help her: before and after each turn, find the count modulo 998 244 353998\,244\,353.

Input

Each test contains multiple test cases. The first line contains tt (1≤t≤1031 \le t \le 10^3), the number of test cases. The first line of each test case contains nn (2≤n≤50002 \le n \le 5000), the number of good pairs. Then nn lines follow, and the ii-th of them contains two integers lil_i and rir_i (1≤li<ri≤2n1 \le l_i < r_i \le 2n), the ii-th clue.

The clues in one test case are pairwise distinct and do not contradict each other. The sum of nn over all test cases does not exceed 50005000.

Output

For each test case, output n+1n+1 integers on one line. The first integer is the count before any clue. For each i≥1i \ge 1, the (i+1)(i+1)-th integer is the count after the ii-th clue. All values are modulo 998 244 353998\,244\,353.

Hints

The first test case of the sample is explained in the statement. The third test case is explained as follows. There are 132132 balanced bracket sequences with 66 good pairs. After the first clue (2,3)(2,3), there are 4242 sequences with that good pair. After the second clue (1,6)(1,6), there are 55 sequences with good pairs (2,3)(2,3) and (1,6)(1,6). After the third clue (7,8)(7,8), there are 22 sequences with those three good pairs: "(()())()(())" and "(()())()()()". After the fourth clue (9,12)(9,12), only "(()())()(())" remains. The counts after the fifth and sixth clues are both 11, since the content of ss is already known.

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