#include <bits/stdc++.h>
using namespace std;
long long t, n, m, num, x[200005], y[200005], fac[200005 << 1],
    invfac[200005 << 1];
set<long long> ans, fucked;
struct segtree {
  long long l, r, siz;
} sgt[200005 << 2];
inline long long read() {
  long long s = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    s = (s << 1) + (s << 3) + ch - '0';
    ch = getchar();
  }
  return s * f;
}
void build(long long p, long long l, long long r) {
  sgt[p].l = l, sgt[p].r = r;
  if (l == r) {
    sgt[p].siz = 1;
    return;
  }
  long long mid = l + r >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
  sgt[p].siz = sgt[p << 1].siz + sgt[p << 1 | 1].siz;
}
void upd(long long p, long long x, long long y) {
  long long l = sgt[p].l, r = sgt[p].r, mid = l + r >> 1;
  if (l == r) {
    sgt[p].siz = y;
    return;
  }
  if (x > mid)
    upd(p << 1 | 1, x, y);
  else
    upd(p << 1, x, y);
  sgt[p].siz = sgt[p << 1].siz + sgt[p << 1 | 1].siz;
}
long long find(long long p, long long k) {
  long long l = sgt[p].l, r = sgt[p].r, mid = l + r >> 1;
  if (l == r) return l;
  if (sgt[p << 1].siz >= k) return find(p << 1, k);
  return find(p << 1 | 1, k - sgt[p << 1].siz);
}
void exgcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1, y = 0;
    return;
  }
  exgcd(b, a % b, y, x);
  y -= (a / b) * x;
}
long long inv(long long a, long long p) {
  long long x, y;
  exgcd(a, p, x, y);
  return (x % p + p) % p;
}
long long C(long long n, long long m) {
  return fac[n] * invfac[m] % 998244353 * invfac[n - m] % 998244353;
}
void init() {
  fac[0] = 1;
  for (long long i = 1; i <= 400000; ++i) fac[i] = fac[i - 1] * i % 998244353;
  invfac[400000] = inv(fac[400000], 998244353);
  for (long long i = 400000; i; --i) invfac[i - 1] = invfac[i] * i % 998244353;
}
signed main() {
  init();
  t = read();
  build(1, 1, 200000);
  while (t--) {
    n = read(), m = read(), ans.clear(), fucked.clear();
    for (long long i = 1; i <= m; ++i) x[i] = read(), y[i] = read();
    for (long long i = m, p; i >= 1; --i) {
      p = find(1, y[i]);
      upd(1, p, 0);
      fucked.insert(p);
      p = find(1, y[i]);
      ans.insert(p);
    }
    for (set<long long>::iterator it = fucked.begin(); it != fucked.end(); ++it)
      upd(1, (*it), 1);
    num = n - 1 - ans.size();
    printf("%lld\n", C(n + num, n));
  }
  return 0;
}
