#include <bits/stdc++.h>
using namespace std;
template <int M>
struct static_mint {
  static_assert(0 < M, "Module must be positive");
  int val;
  static_mint() : val() {}
  static_mint(long long x) : val(x % M) {
    if (val < 0) val += M;
  }
  static_mint pow(long long n) const {
    static_mint ans = 1, x(*this);
    for (; n > 0; n /= 2) {
      if (n & 1) ans *= x;
      x *= x;
    }
    return ans;
  }
  static_mint inv() const { return pow(M - 2); }
  static_mint operator+() const {
    static_mint m;
    m.val = val;
    return m;
  }
  static_mint operator-() const {
    static_mint m;
    m.val = (val == 0 ? 0 : M - val);
    return m;
  }
  static_mint &operator+=(const static_mint &m) {
    if ((val += m.val) >= M) val -= M;
    return *this;
  }
  static_mint &operator-=(const static_mint &m) {
    if ((val -= m.val) < 0) val += M;
    return *this;
  }
  static_mint &operator*=(const static_mint &m) {
    val = (long long)val * m.val % M;
    return *this;
  }
  static_mint &operator/=(const static_mint &m) {
    val = (long long)val * m.inv().val % M;
    return *this;
  }
  friend static_mint operator+(const static_mint &lhs, const static_mint &rhs) {
    return static_mint(lhs) += rhs;
  }
  friend static_mint operator-(const static_mint &lhs, const static_mint &rhs) {
    return static_mint(lhs) -= rhs;
  }
  friend static_mint operator*(const static_mint &lhs, const static_mint &rhs) {
    return static_mint(lhs) *= rhs;
  }
  friend static_mint operator/(const static_mint &lhs, const static_mint &rhs) {
    return static_mint(lhs) /= rhs;
  }
  friend bool operator==(const static_mint &lhs, const static_mint &rhs) {
    return lhs.val == rhs.val;
  }
  friend bool operator!=(const static_mint &lhs, const static_mint &rhs) {
    return lhs.val != rhs.val;
  }
  static_mint &operator++() { return *this += 1; }
  static_mint &operator--() { return *this -= 1; }
  static_mint operator++(int) {
    static_mint result(*this);
    *this += 1;
    return result;
  }
  static_mint operator--(int) {
    static_mint result(*this);
    *this -= 1;
    return result;
  }
  template <typename T>
  explicit operator T() const {
    return T(val);
  }
  friend std::ostream &operator<<(std::ostream &os, const static_mint &m) {
    return os << m.val;
  }
  friend std::istream &operator>>(std::istream &is, static_mint &m) {
    long long x;
    return is >> x, m = x, is;
  }
};
template <typename T, typename L = T>
struct segment_tree {
  using F = std::function<T(const T &, const T &)>;
  int n;
  std::vector<T> t;
  std::vector<L> lazy;
  T e;
  F f;
  segment_tree() : n(), e(), f() {}
  template <typename U>
  segment_tree(const std::vector<U> &v, int n, T e, F f)
      : n(n), t(4 * n), lazy(4 * n), e(e), f(f) {
    build(v, 1, 0, n - 1);
  }
  template <typename U>
  void build(const std::vector<U> &v, int i, int l, int r) {
    if (l == r) {
      t[i] = T(v[l]);
      return;
    }
    int mid = (l + r) >> 1;
    build(v, i << 1, l, mid);
    build(v, i << 1 | 1, mid + 1, r);
    t[i] = f(t[i << 1], t[i << 1 | 1]);
  }
  void push(int x, int l, int r) {
    if (lazy[x]) {
      t[x << 1] += lazy[x];
      t[x << 1 | 1] += lazy[x];
      lazy[x << 1] += lazy[x];
      lazy[x << 1 | 1] += lazy[x];
      lazy[x] = 0;
    }
  }
  template <typename U>
  void update(int idx, const U &val) {
    update_helper(idx, val, 1, 0, n - 1);
  }
  template <typename U>
  void update_helper(int idx, const U &val, int i, int l, int r) {
    if (l == r) {
      t[i] = T(val);
      return;
    }
    push(i, l, r);
    int mid = (l + r) >> 1;
    if (idx <= mid)
      update_helper(idx, val, i << 1, l, mid);
    else
      update_helper(idx, val, i << 1 | 1, mid + 1, r);
    t[i] = f(t[i << 1], t[i << 1 | 1]);
  }
  template <typename U>
  void update(int ql, int qr, const U &val) {
    update_helper(ql, qr, val, 1, 0, n - 1);
  }
  template <typename U>
  void update_helper(int ql, int qr, const U &val, int i, int l, int r) {
    if (r < ql || qr < l) return;
    if (ql <= l && r <= qr) {
      t[i] += val;
      lazy[i] += val;
      return;
    }
    push(i, l, r);
    int mid = (l + r) >> 1;
    update_helper(ql, qr, val, i << 1, l, mid);
    update_helper(ql, qr, val, i << 1 | 1, mid + 1, r);
    t[i] = f(t[i << 1], t[i << 1 | 1]);
  }
  T query(int ql, int qr) { return query_helper(ql, qr, 1, 0, n - 1); }
  T query_helper(int ql, int qr, int i, int l, int r) {
    if (r < ql || qr < l) return e;
    if (ql <= l && r <= qr) return t[i];
    push(i, l, r);
    int mid = (l + r) >> 1;
    T x = query_helper(ql, qr, i << 1, l, mid),
      y = query_helper(ql, qr, i << 1 | 1, mid + 1, r);
    return f(x, y);
  }
  int find_min() { return find_min_helper(1, 0, n - 1); }
  int find_min_helper(int i, int l, int r) {
    if (l == r) {
      return l;
    } else {
      push(i, l, r);
      int mid = (l + r) >> 1;
      if (t[i << 1 | 1] <= t[i << 1]) {
        return find_min_helper(i << 1 | 1, mid + 1, r);
      } else {
        return find_min_helper(i << 1, l, mid);
      }
    }
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  using mint = static_mint<998244353>;
  constexpr int N = 1000000;
  constexpr int inf = (int)1e9;
  vector<mint> fact(N + 1), inv(N + 1);
  fact[0] = inv[0] = 1;
  for (int i = 1; i <= N; i++) {
    fact[i] = i * fact[i - 1];
    inv[i] = fact[i].inv();
  }
  auto C = [&](int n, int k) -> mint { return fact[n] * inv[k] * inv[n - k]; };
  auto partition = [&](int n, int k) -> mint { return C(n + k - 1, k - 1); };
  int t;
  cin >> t;
  vector<int> pos(N, -1);
  while (t--) {
    int n, m;
    cin >> n >> m;
    if (m == 0) {
      mint ans = partition(n - 1, n + 1);
      cout << ans << '\n';
      continue;
    }
    vector<int> x(m), y(m);
    for (int i = 0; i < m; i++) {
      cin >> x[i] >> y[i], --x[i], --y[i];
    }
    segment_tree<int> st(y, m, inf,
                         [&](int i, int j) { return i < j ? i : j; });
    vector<int> actual(m);
    for (int i = 0; i < m; i++) {
      int j = st.find_min();
      actual[j] = st.query(j, j);
      pos[actual[j]] = j;
      st.update(0, j, 1);
      st.update(j, inf);
    }
    int conflict = 0;
    for (int i = 0; i < m; i++) {
      if (actual[i] > 0) {
        if (pos[actual[i] - 1] != -1 && pos[actual[i] - 1] < i) {
          conflict += 1;
        }
      }
    }
    int strict_ineq = m - conflict;
    mint ans = partition(n - strict_ineq - 1, n + 1);
    cout << ans << '\n';
    for (int i = 0; i < m; i++) {
      pos[actual[i]] = -1;
    }
  }
  return 0;
}

### Prompt

Your task is to create a cpp solution to the following problem:

Consider the insertion sort algorithm used to sort an integer sequence [a_1, a_2, …, a_n] of length n in non-decreasing order.

For each i in order from 2 to n, do the following. If a_i ≥ a_{i-1}, do nothing and move on to the next value of i. Otherwise, find the smallest j such that a_i < a_j, shift the elements on positions from j to i-1 by one position to the right, and write down the initial value of a_i to position j. In this case we'll say that we performed an insertion of an element from position i to position j.

It can be noticed that after processing any i, the prefix of the sequence [a_1, a_2, …, a_i] is sorted in non-decreasing order, therefore, the algorithm indeed sorts any sequence.

For example, sorting [4, 5, 3, 1, 3] proceeds as follows: 

  * i = 2: a_2 ≥ a_1, do nothing; 
  * i = 3: j = 1, insert from position 3 to position 1: [3, 4, 5, 1, 3]; 
  * i = 4: j = 1, insert from position 4 to position 1: [1, 3, 4, 5, 3]; 
  * i = 5: j = 3, insert from position 5 to position 3: [1, 3, 3, 4, 5]. 



You are given an integer n and a list of m integer pairs (x_i, y_i). We are interested in sequences such that if you sort them using the above algorithm, exactly m insertions will be performed: first from position x_1 to position y_1, then from position x_2 to position y_2, ..., finally, from position x_m to position y_m.

How many sequences of length n consisting of (not necessarily distinct) integers between 1 and n, inclusive, satisfy the above condition? Print this number modulo 998 244 353.

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^5). Description of the test cases follows.

The first line of each test case contains two integers n and m (2 ≤ n ≤ 2 ⋅ 10^5; 0 ≤ m < n) — the length of the sequence and the number of insertions.

The i-th of the following m lines contains two integers x_i and y_i (2 ≤ x_1 < x_2 < … < x_m ≤ n; 1 ≤ y_i < x_i). These lines describe the sequence of insertions in chronological order.

It is guaranteed that the sum of m over all test cases does not exceed 2 ⋅ 10^5. Note that there is no constraint on the sum of n of the same kind.

Output

For each test case, print the number of sequences of length n consisting of integers from 1 to n such that sorting them with the described algorithm produces the given sequence of insertions, modulo 998 244 353.

Example

Input


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


Output


10
1
21

Note

In the first test case, the algorithm performs no insertions — therefore, the initial sequence is already sorted in non-decreasing order. There are 10 such sequences: [1, 1, 1], [1, 1, 2], [1, 1, 3], [1, 2, 2], [1, 2, 3], [1, 3, 3], [2, 2, 2], [2, 2, 3], [2, 3, 3], [3, 3, 3].

In the second test case, the only sequence satisfying the conditions is [3, 2, 1].

In the third test case, [4, 5, 3, 1, 3] is one of the sought sequences.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <int M>
struct static_mint {
  static_assert(0 < M, "Module must be positive");
  int val;
  static_mint() : val() {}
  static_mint(long long x) : val(x % M) {
    if (val < 0) val += M;
  }
  static_mint pow(long long n) const {
    static_mint ans = 1, x(*this);
    for (; n > 0; n /= 2) {
      if (n & 1) ans *= x;
      x *= x;
    }
    return ans;
  }
  static_mint inv() const { return pow(M - 2); }
  static_mint operator+() const {
    static_mint m;
    m.val = val;
    return m;
  }
  static_mint operator-() const {
    static_mint m;
    m.val = (val == 0 ? 0 : M - val);
    return m;
  }
  static_mint &operator+=(const static_mint &m) {
    if ((val += m.val) >= M) val -= M;
    return *this;
  }
  static_mint &operator-=(const static_mint &m) {
    if ((val -= m.val) < 0) val += M;
    return *this;
  }
  static_mint &operator*=(const static_mint &m) {
    val = (long long)val * m.val % M;
    return *this;
  }
  static_mint &operator/=(const static_mint &m) {
    val = (long long)val * m.inv().val % M;
    return *this;
  }
  friend static_mint operator+(const static_mint &lhs, const static_mint &rhs) {
    return static_mint(lhs) += rhs;
  }
  friend static_mint operator-(const static_mint &lhs, const static_mint &rhs) {
    return static_mint(lhs) -= rhs;
  }
  friend static_mint operator*(const static_mint &lhs, const static_mint &rhs) {
    return static_mint(lhs) *= rhs;
  }
  friend static_mint operator/(const static_mint &lhs, const static_mint &rhs) {
    return static_mint(lhs) /= rhs;
  }
  friend bool operator==(const static_mint &lhs, const static_mint &rhs) {
    return lhs.val == rhs.val;
  }
  friend bool operator!=(const static_mint &lhs, const static_mint &rhs) {
    return lhs.val != rhs.val;
  }
  static_mint &operator++() { return *this += 1; }
  static_mint &operator--() { return *this -= 1; }
  static_mint operator++(int) {
    static_mint result(*this);
    *this += 1;
    return result;
  }
  static_mint operator--(int) {
    static_mint result(*this);
    *this -= 1;
    return result;
  }
  template <typename T>
  explicit operator T() const {
    return T(val);
  }
  friend std::ostream &operator<<(std::ostream &os, const static_mint &m) {
    return os << m.val;
  }
  friend std::istream &operator>>(std::istream &is, static_mint &m) {
    long long x;
    return is >> x, m = x, is;
  }
};
template <typename T, typename L = T>
struct segment_tree {
  using F = std::function<T(const T &, const T &)>;
  int n;
  std::vector<T> t;
  std::vector<L> lazy;
  T e;
  F f;
  segment_tree() : n(), e(), f() {}
  template <typename U>
  segment_tree(const std::vector<U> &v, int n, T e, F f)
      : n(n), t(4 * n), lazy(4 * n), e(e), f(f) {
    build(v, 1, 0, n - 1);
  }
  template <typename U>
  void build(const std::vector<U> &v, int i, int l, int r) {
    if (l == r) {
      t[i] = T(v[l]);
      return;
    }
    int mid = (l + r) >> 1;
    build(v, i << 1, l, mid);
    build(v, i << 1 | 1, mid + 1, r);
    t[i] = f(t[i << 1], t[i << 1 | 1]);
  }
  void push(int x, int l, int r) {
    if (lazy[x]) {
      t[x << 1] += lazy[x];
      t[x << 1 | 1] += lazy[x];
      lazy[x << 1] += lazy[x];
      lazy[x << 1 | 1] += lazy[x];
      lazy[x] = 0;
    }
  }
  template <typename U>
  void update(int idx, const U &val) {
    update_helper(idx, val, 1, 0, n - 1);
  }
  template <typename U>
  void update_helper(int idx, const U &val, int i, int l, int r) {
    if (l == r) {
      t[i] = T(val);
      return;
    }
    push(i, l, r);
    int mid = (l + r) >> 1;
    if (idx <= mid)
      update_helper(idx, val, i << 1, l, mid);
    else
      update_helper(idx, val, i << 1 | 1, mid + 1, r);
    t[i] = f(t[i << 1], t[i << 1 | 1]);
  }
  template <typename U>
  void update(int ql, int qr, const U &val) {
    update_helper(ql, qr, val, 1, 0, n - 1);
  }
  template <typename U>
  void update_helper(int ql, int qr, const U &val, int i, int l, int r) {
    if (r < ql || qr < l) return;
    if (ql <= l && r <= qr) {
      t[i] += val;
      lazy[i] += val;
      return;
    }
    push(i, l, r);
    int mid = (l + r) >> 1;
    update_helper(ql, qr, val, i << 1, l, mid);
    update_helper(ql, qr, val, i << 1 | 1, mid + 1, r);
    t[i] = f(t[i << 1], t[i << 1 | 1]);
  }
  T query(int ql, int qr) { return query_helper(ql, qr, 1, 0, n - 1); }
  T query_helper(int ql, int qr, int i, int l, int r) {
    if (r < ql || qr < l) return e;
    if (ql <= l && r <= qr) return t[i];
    push(i, l, r);
    int mid = (l + r) >> 1;
    T x = query_helper(ql, qr, i << 1, l, mid),
      y = query_helper(ql, qr, i << 1 | 1, mid + 1, r);
    return f(x, y);
  }
  int find_min() { return find_min_helper(1, 0, n - 1); }
  int find_min_helper(int i, int l, int r) {
    if (l == r) {
      return l;
    } else {
      push(i, l, r);
      int mid = (l + r) >> 1;
      if (t[i << 1 | 1] <= t[i << 1]) {
        return find_min_helper(i << 1 | 1, mid + 1, r);
      } else {
        return find_min_helper(i << 1, l, mid);
      }
    }
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  using mint = static_mint<998244353>;
  constexpr int N = 1000000;
  constexpr int inf = (int)1e9;
  vector<mint> fact(N + 1), inv(N + 1);
  fact[0] = inv[0] = 1;
  for (int i = 1; i <= N; i++) {
    fact[i] = i * fact[i - 1];
    inv[i] = fact[i].inv();
  }
  auto C = [&](int n, int k) -> mint { return fact[n] * inv[k] * inv[n - k]; };
  auto partition = [&](int n, int k) -> mint { return C(n + k - 1, k - 1); };
  int t;
  cin >> t;
  vector<int> pos(N, -1);
  while (t--) {
    int n, m;
    cin >> n >> m;
    if (m == 0) {
      mint ans = partition(n - 1, n + 1);
      cout << ans << '\n';
      continue;
    }
    vector<int> x(m), y(m);
    for (int i = 0; i < m; i++) {
      cin >> x[i] >> y[i], --x[i], --y[i];
    }
    segment_tree<int> st(y, m, inf,
                         [&](int i, int j) { return i < j ? i : j; });
    vector<int> actual(m);
    for (int i = 0; i < m; i++) {
      int j = st.find_min();
      actual[j] = st.query(j, j);
      pos[actual[j]] = j;
      st.update(0, j, 1);
      st.update(j, inf);
    }
    int conflict = 0;
    for (int i = 0; i < m; i++) {
      if (actual[i] > 0) {
        if (pos[actual[i] - 1] != -1 && pos[actual[i] - 1] < i) {
          conflict += 1;
        }
      }
    }
    int strict_ineq = m - conflict;
    mint ans = partition(n - strict_ineq - 1, n + 1);
    cout << ans << '\n';
    for (int i = 0; i < m; i++) {
      pos[actual[i]] = -1;
    }
  }
  return 0;
}

```