#include <bits/stdc++.h>
struct Treap {
  Treap *l, *r;
  int w, k, lz;
  Treap() {}
  Treap(int _k) : l(0), r(0), w(1), k(_k), lz(0) {}
} tp_node[262144];
void pull(Treap *p) { p->w = 1 + (p->l ? p->l->w : 0) + (p->r ? p->r->w : 0); }
void push(Treap *p) {
  if (p->l) p->l->lz += p->lz;
  if (p->r) p->r->lz += p->lz;
  p->k += p->lz, p->lz = 0;
}
Treap *merge(Treap *p, Treap *q) {
  if (!p || !q) return p ? p : q;
  return rand() % (p->w + q->w) < p->w
             ? (push(p), p->r = merge(p->r, q), pull(p), p)
             : (push(q), q->l = merge(p, q->l), pull(q), q);
}
std::pair<Treap *, Treap *> split(Treap *p, int k) {
  if (!p) return {0, 0};
  Treap *l, *m, *r;
  push(p);
  if (p->k < k)
    std::tie(m, r) = split(p->r, k), p->r = 0, pull(p), l = merge(p, m);
  else
    std::tie(l, m) = split(p->l, k), p->l = 0, pull(p), r = merge(m, p);
  return {l, r};
}
int inv(int a) {
  int k = 998244353 - 2;
  int r = 1;
  while (k) {
    if (k & 1) r = (long long int)r * a % 998244353;
    a = (long long int)a * a % 998244353;
    k >>= 1;
  }
  return r;
}
int fac[262144 * 2];
int comb(int n, int m) {
  return (long long int)fac[n] * inv(fac[n - m]) % 998244353 * inv(fac[m]) %
         998244353;
}
int y[262144];
int main() {
  fac[0] = 1;
  for (int i = 1; i < 262144 * 2; ++i)
    fac[i] = (long long int)fac[i - 1] * i % 998244353;
  int T;
  scanf("%d", &T);
  for (int tc = 1; tc <= T; ++tc) {
    int n, m;
    scanf("%d%d", &n, &m);
    Treap *rt = 0;
    for (int i = 0; i < m; ++i) scanf("%*d%d", &y[i]);
    for (int i = 0; i < m; ++i) {
      Treap *pl, *pr;
      std::tie(pl, rt) = split(rt, y[i] - 1);
      std::tie(rt, pr) = split(rt, y[i]);
      if (pr) pr->lz += 1;
      rt = new (tp_node + i) Treap(y[i]);
      rt = merge(pl, rt);
      rt = merge(rt, pr);
    }
    int k = rt ? rt->w : 0;
    k = n - 1 - k;
    0;
    int ans = comb(n + k, k);
    printf("%d\n", ans);
  }
  return 0;
}
