#include <bits/stdc++.h>
using namespace std;
const int mod = 5318008;
int main() {
int T;
cin >> T;
while (T--) {
int n;
int x1, y1, x2, y2;
cin >> n >> x1 >> y1 >> x2 >> y2;
if (abs(x1-x2) < abs(y2-y1)) {
swap(x1, y1);
swap(x2, y2);
}
if (x2 < x1) {
swap(x1, x2);
swap(y1, y2);
}
x1--;
y1--;
x2--;
y2--;
vector<int> prev(n);
vector<int> cur(n);
int x = x1;
prev[y1] = 1;
for (; x < x2; x++) {
//cur = move(vector<int>(n));
cur[0] = (prev[0] + prev[1]) % mod;
cur[n-1] = (prev[n-1] + prev[n-2]) % mod;
for (int y = 1; y < n-1; y++) {
cur[y] = (prev[y-1] + prev[y] + prev[y+1]) % mod;
}
//for (int i : cur) cout << i << "\t"; cout << endl;
swap(prev, cur);
}
cout << prev[y2] << "\n";
}
}