#include <bits/stdc++.h>
using namespace std;
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define endl '\n'
#define yes cout << "yes\n"
#define no cout << "no\n"
#define rep(i,a,b) for(int i=a;i<b;++i)
#define per(i,a,b) for(int i=b-1;i>=a;--i)
#define each(x, a) for (auto& x : a)
const int INF = 1e18;
const int MOD = 998244353;
const int N = 3e5 + 5;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return (a / gcd(a, b)) * b; }
int power(int a, int b, int m = MOD) {
int res = 1;
while (b > 0) {
if (b & 1) res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
int modinv(int a, int m = MOD) {
return power(a, m - 2, m);
}
void solve() {
int n, m;
cin >> n >> m;
vector<int> limit(n + 1, 0);
rep(i, 0, m) {
int l, r;
cin >> l >> r;
limit[r] = max(limit[r], l);
}
rep(i, 1, n + 1) {
limit[i] = max(limit[i], limit[i - 1]);
}
vector<int> dp(n + 1, 0);
vector<int> sdp(n + 1, 0);
dp[0] = 1;
sdp[0] = 1;
rep(i, 1, n + 1) {
int l = limit[i];
int r = i - 1;
if (l <= r) {
int current_sum = sdp[r];
int prev_sum = (l > 0) ? sdp[l - 1] : 0;
dp[i] = (current_sum - prev_sum + MOD) % MOD;
} else {
dp[i] = 0;
}
sdp[i] = (sdp[i - 1] + dp[i]) % MOD;
}
cout << (2 * dp[n]) % MOD << endl;
}
int32_t main() {
fast_io;
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojZGVmaW5lIGZhc3RfaW8gaW9zOjpzeW5jX3dpdGhfc3RkaW8oMCk7IGNpbi50aWUoMCk7IGNvdXQudGllKDApCgojZGVmaW5lIG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gbiwgbTsKICAgIGNpbiA+PiBuID4+IG07CiAgICB2ZWN0b3I8aW50PiBsaW1pdChuICsgMSwgMCk7CiAgICByZXAoaSwgMCwgbSkgewogICAgICAgIGludCBsLCByOwogICAgICAgIGNpbiA+PiBsID4+IHI7CiAgICAgICAgbGltaXRbcl0gPSBtYXgobGltaXRbcl0sIGwpOwogICAgfQogICAgcmVwKGksIDEsIG4gKyAxKSB7CiAgICAgICAgbGltaXRbaV0gPSBtYXgobGltaXRbaV0sIGxpbWl0W2kgLSAxXSk7CiAgICB9CiAgICB2ZWN0b3I8aW50PiBkcChuICsgMSwgMCk7CiAgICB2ZWN0b3I8aW50PiBzZHAobiArIDEsIDApOwogICAgZHBbMF0gPSAxOwogICAgc2RwWzBdID0gMTsKICAgIHJlcChpLCAxLCBuICsgMSkgewogICAgICAgIGludCBsID0gbGltaXRbaV07CiAgICAgICAgaW50IHIgPSBpIC0gMTsKICAgICAgICBpZiAobCA8PSByKSB7CiAgICAgICAgICAgIGludCBjdXJyZW50X3N1bSA9IHNkcFtyXTsKICAgICAgICAgICAgaW50IHByZXZfc3VtID0gKGwgPiAwKSA/IHNkcFtsIC0gMV0gOiAwOwogICAgICAgICAgICBkcFtpXSA9IChjdXJyZW50X3N1bSAtIHByZXZfc3VtICsgTU9EKSAlIE1PRDsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBkcFtpXSA9IDA7CiAgICAgICAgfQogICAgICAgIHNkcFtpXSA9IChzZHBbaSAtIDFdICsgZHBbaV0pICUgTU9EOwogICAgfQogICAgY291dCA8PCAoMiAqIGRwW25dKSAlIE1PRCA8PCBlbmRsOwp9CgppbnQzMl90IG1haW4oKSB7CiAgICBmYXN0X2lvOwoKICAgIGludCB0OwogICAgY2luID4+IHQ7CiAgICB3aGlsZSAodC0tKSB7CiAgICAgICAgc29sdmUoKTsKICAgIH0KCiAgICByZXR1cm4gMDsKfQ==