#include <bits/stdc++.h>
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
ll gcd(ll n, ll m) {
  ll tmp;
  while (m != 0) {
    tmp = n % m;
    n = m;
    m = tmp;
  }
  return n;
}
ll lcm(ll n, ll m) { return abs(n) / gcd(n, m) * abs(m); }
using namespace std;
void solve() {
  int t;
  cin >> t;
  while (t--) {
    ll n, k;
    cin >> n >> k;
    ll l1, r1, l2, r2;
    cin >> l1 >> r1 >> l2 >> r2;
    ll ans = INF;
    ll len = max(0LL, min(r1, r2) - max(l1, l2));
    k -= len * n;
    if (k <= 0) {
      cout << 0 << "\n";
      continue;
    }
    ll ini = max(0LL, max(l1, l2) - min(r1, r2));
    ll x = max(r1, r2) - min(l1, l2) - len;
    ll res = 0, cost = 0;
    res += min(k, x);
    cost += min(k, x) + ini;
    ll y = max(0LL, (k - res));
    res += y;
    cost += 2 * y;
    chmin(ans, cost);
    if (x * n >= k && x != 0) {
      res = 0;
      cost = 0;
      res += k / x * x;
      cost += k / x * (x + ini);
      res += k % x;
      cost += k % x + ini;
      chmin(ans, cost);
    }
    if (x != 0 && k / x > 0) {
      res = 0, cost = 0;
      res += min(n, k / x) * x;
      cost += min(n, k / x) * (ini + x);
      ll kk = max(0LL, k - res);
      res += kk;
      cost += kk * 2;
      chmin(ans, cost);
    }
    cout << ans << "\n";
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);
  solve();
  return 0;
}
