8551: Yet Another Easy Permutation Count Problem

内存限制:128 MB 时间限制:15 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

Silver187 likes Permutation. For a permutation PP of length nn, a position x(2xn1) is a good position if and only if P_xPi<Px, andPx>Px+1. In particular:

  1. position 11 is a good position if and only if P1>P2 and n2.
  2. position nn can never be a good position.

Silver187 wants to calculate the beauty value of a permutation PP of length nn. He defines a number SS, initially S=0S=0. Silver187 will repeat the following operations for the permutation PP until the permutation PP is in ascending order.

  1. Add to SS the number of good positions in the current permutaion PP.
  2. Do a bubble sort on the permutation P(For each ii from 1 to n - 1in order, if Pi > Pi+1, swap PiPi+1).

SS is the beautiful value of the permutation PP.

Silver187 gives you two numbers nn and mm. There are mm constraints. Every constraint will give xx and yy, which means the inital number of position xx is yy. Find the sum of the beauty values of all permutations that satisfy all constraints modulo 998244353.

输入格式

The first line has one integer T(1≤T≤100), indicating there are T test cases.

In each case:

The first line contains two integers n(1n106)m(0mn)---the length of the permutation and the number of constraints.

The ii-th line of the next mm line contains two integers---the i-th constraint.

It is guaranteed that there is at least one permutation that satisfies all constraints.

Input guarantee 1mn107.

输出格式

In each case, output a single integer---the sum of the beautiful values of all permutations that satisfy the constraints modulo 998244353

输入样例 复制

2
3 1
1 2
7 5
4 5
2 2
6 7
3 3
1 4

输出样例 复制

3
13