#include <bits/stdc++.h>
using namespace std;
int t, n;
long long l1, l2, r1, r2, k;
long long solve() {
  long long l = max(l1, l2), r = min(r1, r2), ans = 0;
  if (l <= r) {
    k -= (r - l) * n;
    if (k <= 0) return 0;
    long long cnt1 = (abs(r2 - r1) + abs(l1 - l2)) * n;
    ans += min(k, cnt1);
    k -= min(k, cnt1);
    return ans + k * 2;
  }
  if (l1 > l2) swap(l1, l2), swap(r1, r2);
  long long cnt = abs(r2 - l1);
  ans = abs(l2 - r1) + min(cnt, k);
  k -= min(k, cnt);
  n--;
  while (k > 0 && n--) {
    long long mn = min(k, cnt);
    ans += min(mn * 2, abs(l2 - r1) + mn);
    k -= mn;
  }
  return ans + max(k, 0LL) * 2;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n >> k;
    cin >> l1 >> r1 >> l2 >> r2;
    cout << solve() << "\n";
  }
}
