#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll M = 1000000007;
const ll M1 = 998244353;
const int height = 40;
using vl = vector<ll>;
using pll = pair<ll, ll>;
ll power(ll x, ll y) {
  if (y == 0) return 1;
  ll res = power(x, y / 2);
  res = (res * res);
  if (y & 1) res = (res * x);
  return res;
}
ll powermod(ll x, ll y, ll mod) {
  if (y == 0) return 1;
  ll res = powermod(x, y / 2, mod);
  res = (res * res) % mod;
  if (y & 1) res = (res * x) % mod;
  return res;
}
ll findxor(ll a) {
  switch (a & 3) {
    case 0:
      return a;
    case 1:
      return 1;
    case 2:
      return a + 1;
    case 3:
      return 0;
  }
  return -1;
}
void solve() {
  ll n, k;
  cin >> n >> k;
  ll x, y;
  vector<pair<int, int>> v;
  for (int i = 0; i < 2; i++) {
    cin >> x >> y;
    v.push_back({x, y});
  }
  sort(v.begin(), v.end());
  ll per_value = max(0, min(v[0].second, v[1].second) - v[1].first);
  if (per_value * n >= k) {
    cout << 0 << endl;
    return;
  }
  ll extra = max(0, v[1].first - v[0].second),
     tot = abs(v[0].first - v[1].first) + abs(v[0].second - v[1].second);
  ll mi = extra;
  ll va = max(v[0].second, v[1].second) - v[0].first;
  if (k - (n - 1) * per_value <= va) {
    mi += k - (n)*per_value;
    cout << mi << endl;
    return;
  }
  mi = tot;
  mi += 2 * (k - (n - 1) * per_value - va);
  for (ll i = 2; i <= n; i++) {
    ll cost = extra;
    if (k - (n - i) * per_value <= i * va) {
      cost += (i - 1) * tot + k - (n - i + 1) * per_value - (i - 1) * va;
      mi = min(mi, cost);
      break;
    }
    cost = tot * i;
    cost += 2 * (k - (n - i) * (per_value)-i * va);
    mi = min(mi, cost);
  }
  if (k >= n * va) mi = min(mi, tot * n + 2 * (k - n * va));
  cout << mi << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
