#include <bits/stdc++.h>
using namespace std;
const int N = 600010;
const int mod = 998244353;
long long mpow(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % mod;
    b >>= 1;
    a = a * a % mod;
  }
  return ans;
}
int fac[N], inv[N];
int com(int n, int m) {
  if (n < m) return 0;
  return (long long)fac[n] * inv[m] % mod * inv[n - m] % mod;
}
int c[N], a[N], b[N];
int lowbit(int x) { return x & (-x); }
void insert(int &x, int y) {
  for (int i = x; i < N; i += lowbit(i)) c[i] += y;
}
int query(int x) {
  int sum = 0, pos = 0;
  for (int i = 17; i >= 0; i--) {
    if ((pos | (1 << i)) >= N) continue;
    if (sum + c[pos | (1 << i)] >= x) continue;
    pos |= (1 << i);
    sum += c[pos];
  }
  return pos + 1;
}
void solve() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) scanf("%d%d", &a[i], &b[i]);
  set<int> st;
  stack<int> stk;
  for (int i = m; i >= 1; i--) {
    int pos = query(b[i]);
    stk.push(pos);
    insert(pos, -1);
    pos = query(b[i]);
    st.insert(pos);
  }
  int tot = st.size();
  int ans = com(2 * n - tot - 1, n);
  printf("%d\n", ans);
  while (!stk.empty()) {
    int x = stk.top();
    stk.pop();
    insert(x, 1);
  }
}
int main() {
  fac[0] = inv[0] = 1;
  for (int i = 1; i < N; i++) {
    fac[i] = fac[i - 1] * (long long)i % mod;
    inv[i] = mpow(fac[i], mod - 2);
  }
  for (int i = 1; i < N; i++) insert(i, 1);
  int t;
  scanf("%d", &t);
  while (t--) solve();
  return 0;
}
