logo AlgoBeat OnlineJudge
登录 注册

#214052. [EC Final 2019] Permutation

内存限制:256 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

You are given a permutation . You can do the following operations repeatedly:

  • Choose an interval where is the smallest element in this interval, you can permutate in arbitrary way.
  • Choose an interval where is the smallest element in this interval, you can permutate in arbitrary way.

You want to know how many distinct permutations you can get using operations. The answer can be large, output the answer modulo .

输入格式

The first line contains an integer denoting the number of test cases ().

The first line in a test case contains two integers and (, ). The sum of over all test cases does not exceed .

The second line in a test case contains a permutation ().

输出格式

For each test case, output one line containing the answer modulo .

样例

样例输入 1

5
5 3
3 4 2 1 5
5 4
4 2 1 3 5
5 2
4 5 3 1 2
5 3
4 3 2 1 5
5 2
2 3 1 5 4

样例输出 1

6
1
4
6
4