#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    long long l1, l2, r1, r2;
    cin >> l1 >> r1 >> l2 >> r2;
    long long inte = min(r1, r2);
    inte -= max(l1, l2);
    long long taken = 0, curr = 0;
    long long to = max(r1, r2) - min(l1, l2);
    if (inte > 0) {
      if (inte * n >= k) {
        cout << "0" << endl;
        continue;
      }
      k = k - inte * n;
      if ((to - inte) * n >= k) {
        cout << k << endl;
        continue;
      }
      cout << (to - inte) * n + (k - (to - inte) * n) * 2LL << endl;
      continue;
    }
    long long ans = 100000000000000007;
    long long tmp = 0;
    for (int i = 0; i < n; i++) {
      tmp += taken;
    }
    for (int i = 0; i < n; i++) {
      taken += -1LL * inte;
      if (curr + to >= k) {
        cout << min(ans, taken + k - curr) << endl;
        goto h;
      }
      curr += to;
      taken = taken + to;
      ans = min(ans, taken + (k - curr) * 2LL);
    }
    cout << min(ans, taken + (k - curr) * 2LL) << endl;
  h:;
  }
  return 0;
}
