#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9;
const long long inf64 = 1e18;
const long long MOD = inf + 7;
void solve() {
  long long n, k;
  cin >> n >> k;
  long long l1, r1, l2, r2;
  cin >> l1 >> r1 >> l2 >> r2;
  if (l1 > l2) {
    swap(l1, l2);
    swap(r1, r2);
  }
  long long L = l2;
  long long R = min(r1, r2);
  long long cur = max(0LL, R - L);
  long long one = max(r1, r2) - l1 - cur;
  long long ans = LLONG_MAX;
  for (long long i = 1; i < n + 1; i++) {
    long long have = cur * n;
    long long oneava = one * i;
    long long time = max(0LL, l2 - r1) * i;
    if (k > have) {
      long long extraneed = k - have;
      long long used = min(extraneed, oneava);
      time += used;
      extraneed -= used;
      time += 2 * extraneed;
    }
    ans = min(ans, time);
  }
  cout << ans << "\n";
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) solve();
}
