#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MOD = 998244353;
void solve() {
int n, m;
if (!(cin >> n >> m)) return;
// limit[i] will store the rightmost 'l' for all constraints ending at or before 'i'.
vector<int> limit(n + 1, 0);
for (int i = 0; i < m; ++i) {
int l, r;
cin >> l >> r;
limit[r] = max(limit[r], l);
}
// Propagate the limit constraints. If a block ending at i-1 requires j >= L,
// a block ending at i (which encompasses constraints ending <= i-1) must also satisfy that.
for (int i = 1; i <= n; ++i) {
limit[i] = max(limit[i], limit[i - 1]);
}
// dp[i] = number of valid sequences of length i ending with a block boundary at i
// sum_dp[i] = prefix sum of dp array
vector<int> dp(n + 1, 0);
vector<int> sum_dp(n + 1, 0);
dp[0] = 1;
sum_dp[0] = 1;
for (int i = 1; i <= n; ++i) {
// The previous block must have ended at some index j.
// The current block is s[j+1 ... i].
// For this block to be valid, it must not fully contain any forbidden constraint.
// This implies j must be >= limit[i].
// Also obviously j < i (j max is i-1).
int l = limit[i];
int r = i - 1;
if (l <= r) {
// Calculate sum(dp[l] ... dp[r])
int current_sum = sum_dp[r];
int prev_sum = (l > 0) ? sum_dp[l - 1] : 0;
dp[i] = (current_sum - prev_sum + MOD) % MOD;
} else {
dp[i] = 0;
}
sum_dp[i] = (sum_dp[i - 1] + dp[i]) % MOD;
}
// Multiply by 2 because the sequence can start with either '0' or '1'
cout << (2LL * dp[n]) % MOD << "\n";
}
int main() {
// Optimize I/O operations
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
if (cin >> t) {
while (t--) {
solve();
}
}
return 0;
}