#include <bits/stdc++.h>
using namespace std;
const bool ready = []() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(12);
  return true;
}();
using ld = long double;
const ld PI = acos((ld)-1);
using ll = long long;
using pii = pair<ll, ll>;
using pdd = pair<ld, ld>;
using vd = vector<ld>;
using vb = vector<bool>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;
const ll INF = 1e18;
void solve() {
  ll n;
  cin >> n;
  ;
  ll k;
  cin >> k;
  ;
  vi l(2);
  vi r(2);
  cin >> l[0] >> r[0] >> l[1] >> r[1];
  if (l[0] > l[1]) {
    swap(l[0], l[1]);
    swap(r[0], r[1]);
  }
  const ll over = max(0LL, min(r[0] - l[0], min(r[1] - l[1], r[0] - l[1])));
  k -= n * over;
  if (k <= 0) {
    cout << 0 << "\n";
    return;
  }
  const ll dist = max(0LL, l[1] - r[0]);
  const ll extend = max(r[0], r[1]) - l[0] - over;
  ll ans = INF;
  for (ll i = 0; i < n; i++) {
    ll lans = (i + 1) * dist + i * extend + min(k, extend);
    k = max(k - extend, 0LL);
    ans = min(ans, lans + k * 2);
  }
  cout << ans << "\n";
}
signed main() {
  ll t;
  cin >> t;
  ;
  while (t--) solve();
}
