#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VL = vector<LL>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
void dout() { cerr << endl; }
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
  cerr << H << ' ';
  dout(T...);
}
LL intersection(PLL a, PLL b) {
  PLL c{max(a.first, b.first), min(a.second, b.second)};
  return max(0LL, c.second - c.first);
}
LL dist(PLL a, PLL b) {
  if (intersection(a, b) > 0) return 0;
  if (a.second < b.first) return b.first - a.second;
  if (b.second < a.first) return a.first - b.second;
  return 0;
}
LL outer_d(PLL a, PLL b) {
  PLL c{min(a.first, b.first), max(a.second, b.second)};
  return c.second - c.first;
}
void solve() {
  LL n, k;
  cin >> n >> k;
  PLL a, b;
  cin >> a.first >> a.second;
  cin >> b.first >> b.second;
  LL in = intersection(a, b);
  if (in * n >= k) {
    cout << 0 << "\n";
    return;
  }
  k -= in * n;
  LL d = dist(a, b);
  LL od = outer_d(a, b);
  LL cur = k;
  LL ans = 1e18;
  for (int i = (0); i < (n); ++i) {
    cur += d;
    k -= od - in;
    k = max(k, 0LL);
    ans = min(ans, cur + k);
  }
  cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
