Under construction

Still being built. Things may change

Random Permutation

Time limit10sMemory limit2048 MB

Summary
Count the distinct sequences of minimums obtainable from a random permutation by removing one end element each step, modulo 998244353.
Level

Medium7 of 10

Topics
Dynamic programming, Recursion, Array
Solved
No attempts yet

Problem

You are given a permutation pp consisting of nn integers from 11 to nn. You want to build a sequence aa from pp. To do that, you perform the following operation nn times:

  • append the minimum element of pp to the end of aa;
  • remove one of the ends of pp (either left or right).

You are given a random permutation pp. Your task is to calculate the number of different sequences aa that can be obtained in the way described above. This number can be very large, so find it modulo 998 244 353998\,244\,353. Two sequences are different if there is a position at which these sequences differ.

A permutation of size nn is a sequence of nn distinct integers from 11 to nn.

Input

The first line contains an integer tt (1≤t≤2⋅1051 \le t \le 2 \cdot 10^5), the number of test cases. The test cases follow.

The first line of each test case contains an integer nn, the size of the permutation (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5). The next line contains the permutation itself: nn distinct integers from 11 to nn. The permutation is generated using a pseudorandom number generator.

The sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

Output

For each test case, output a line with a single integer: the required number modulo 998 244 353998\,244\,353.

Examples1

  1. Example 1

    Input
    4
    5
    4 3 5 1 2
    5
    5 3 1 2 4
    2
    2 1
    3
    1 3 2
    
    Expected output
    8
    7
    2
    4