#include <bits/stdc++.h>
using namespace std;
long long intersect(long long l1, long long r1, long long l2, long long r2) {
  if (l1 <= l2 && r1 <= l2) return 0;
  if (l2 <= l1 && r2 <= l1) return 0;
  if (l1 >= l2 && r1 <= r2) return r1 - l1;
  if (l2 >= l1 && r2 <= r1) return r2 - l2;
  if (r1 >= l2 && l1 <= l2) return r1 - l2;
  return r2 - l1;
}
long long unio(long long l1, long long r1, long long l2, long long r2) {
  return r1 - l1 + r2 - l2 - intersect(l1, r1, l2, r2);
}
void test() {
  while (1) {
    long long l1, r1, l2, r2;
    cin >> l1 >> r1 >> l2 >> r2;
    cout << "intersect: " << intersect(l1, r1, l2, r2) << "\n";
    cout << "union: " << unio(l1, r1, l2, r2) << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    long long k, l1, r1, l2, r2;
    cin >> n >> k >> l1 >> r1 >> l2 >> r2;
    long long curr = intersect(l1, r1, l2, r2) * n;
    if (curr >= k) {
      cout << 0 << "\n";
      continue;
    }
    long long ans = 1e18;
    long long to_touch;
    if (l1 <= l2 && r1 <= l2)
      to_touch = l2 - r1, r1 = l2;
    else if (l2 <= l1 && r2 <= l1)
      to_touch = l1 - r2, r2 = l1;
    else
      to_touch = 0;
    long long takeable = unio(l1, r1, l2, r2) - intersect(l1, r1, l2, r2);
    for (int i = 0; i < n; i++) {
      if (curr >= k) break;
      if (k - curr < takeable)
        ans = min(ans, to_touch * (i + 1) + takeable * i + k - curr);
      else
        ans = min(ans, to_touch * (i + 1) + takeable * (i + 1) +
                           2 * (k - curr - takeable));
      curr += takeable;
    }
    cout << ans << "\n";
  }
}
