#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long t;
  cin >> t;
  while (t--) {
    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 s1 = 0, s2 = 0;
    if (l2 >= r1) s1 = l2 - r1;
    long long intersect = 0;
    if (l2 <= r1) intersect = min(r1, r2) - l2;
    s2 = r1 - l1 + r2 - l2 - intersect * 2;
    if (intersect * n >= k) {
      cout << "0\n";
      continue;
    }
    if (s1 && k <= s1) {
      cout << s1 + k << '\n';
      continue;
    }
    long long ans = 1e18;
    for (long long i = 1; i <= n; i++) {
      long long cnt = 0, now = intersect * n;
      cnt += i * s1 * 2;
      now += i * s1;
      if (now >= k) {
        ans = min(ans, cnt);
        break;
      }
      if (now + i * s2 >= k) {
        cnt += k - now;
        ans = min(ans, cnt);
        continue;
      }
      cnt += i * s2;
      now += i * s2;
      cnt += (k - now) * 2;
      ans = min(ans, cnt);
    }
    cout << ans << '\n';
  }
  return 0;
}
