#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long int n, k;
long long int l_1, r_1, l_2, r_2;
long long int solve(void) {
  cin >> n >> k;
  long long int ans = 1e18;
  cin >> l_1 >> r_1 >> l_2 >> r_2;
  if (l_1 > l_2) swap(l_1, l_2), swap(r_1, r_2);
  if (r_1 >= l_2) {
    long long int init = (min(r_1, r_2) - l_2) * n;
    if (init >= k) return 0;
    long long int uni = max(r_1, r_2) - min(l_1, l_2);
    if (uni * n >= k) return k - init;
    return (uni * n - init) + 2LL * (k - uni * n);
  } else {
    for (long long int i = 1; i <= n; i++) {
      long long int cur = 0;
      cur += (l_2 - r_1) * i;
      long long int uni = (r_2 - l_1) * i;
      if (uni >= k)
        ans = min(ans, cur + k);
      else
        ans = min(ans, cur + uni + 2 * (k - uni));
    }
    return ans;
  }
}
int main(void) {
  int i, tc;
  cin >> tc;
  while (tc--) cout << solve() << "\n";
  return 0;
}
