#include <bits/stdc++.h>
using namespace std;
bool ava(int a,int b,int c){
return abs(b-a) >= c;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int q;
cin >> q;
while(q--){
int t,n,k,x,y;
cin >> t >> n >> k >> x >> y;
int dis;
if (x > y) swap(x,y);
if (t == 0) {
cout << y-x << "\n";
continue;
}
if (k >= n) {
dis = -1;
} else if (y-x >= k){
dis = 1;
} else {
if (ava(x,n,k) && ava(y,n,k)){
dis = 2;
} else if (ava(x,1,k) && ava(y,1,k)){
dis = 2;
} else {
bool flag1 = (ava(x,1,k) || ava(x,n,k));
bool flag2 = (ava(y,1,k) || ava(y,n,k));
if (flag1 && flag2) {
dis = 3;
} else {
dis = -1
}
}
}
if (dis == -1) {
cout << -1 << "\n"; continue;
} else if (t == 1){
cout << dis << "\n"; continue;
}else if (t == 2){
if (dis >= k) {
cout << 1 << "\n"; continue;
} else {
cout << -1 << "\n"; continue;
}
} else {
cout << -1 << "\n"; continue;
}
}
return 0;
}