#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#define ll long long
#define F first
#define S second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define EPS 1.0e-8
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {
cin >> p.first;
return cin >> p.second;
}
ll fastpow(ll base, ll power, ll M){
if (power == 0) return 1;
if (power == 1) return base;
ll val = fastpow(base, power / 2, M);
return (power % 2 == 0) ? (val * val) % M : (((val * val) % M) * base) % M;
}
inline void debugMode() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
const int N = 1e5 + 5;
const int MOD = 1e9 + 7;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int main(){
debugMode();
int t; cin >> t;
while(t--){
int n, x1, y1, x2, y2;
cin >> n >> x1 >> y1 >> x2 >> y2;
int diff1 = min({x1 - 1, n - x1, y1 - 1, n - y1});
int diff2 = min({x2 - 1, n - x2, y2 - 1, n - y2});
cout << abs(diff1 - diff2) << '\n';
}
return 0;
}
1711B - Party | 1702D - Not a Cheap String |
1714F - Build a Tree and That Is It | 1703F - Yet Another Problem About Pairs Satisfying an Inequality |
610A - Pasha and Stick | 1200A - Hotelier |
1091A - New Year and the Christmas Ornament | 1352B - Same Parity Summands |
1102A - Integer Sequence Dividing | 630B - Moore's Law |
1004A - Sonya and Hotels | 1680B - Robots |
1690A - Print a Pedestal (Codeforces logo) | 1295A - Display The Number |
1077A - Frog Jumping | 1714G - Path Prefixes |
1369C - RationalLee | 289B - Polo the Penguin and Matrix |
1716A - 2-3 Moves | 1670B - Dorms War |
1716B - Permutation Chain | 987A - Infinity Gauntlet |
1676G - White-Black Balanced Subtrees | 1716D - Chip Move |
1352F - Binary String Reconstruction | 1487B - Cat Cycle |
1679C - Rooks Defenders | 56A - Bar |
1694B - Paranoid String | 35A - Shell Game |