#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int T;
  cin >> T;
  while (T--) {
    long long n, k, l1, r1, l2, r2;
    cin >> n >> k >> l1 >> r1 >> l2 >> r2;
    long long in1 = max(0ll, min(r1, r2) - max(l1, l2));
    if (in1 * n >= k) {
      cout << 0 << endl;
      continue;
    }
    long long len2 = (in1 ? 0ll : max(l1, l2) - min(r1, r2));
    long long in2 = max(r1, r2) - min(l1, l2);
    long long step2 = (in1 ? in2 - in1 : in2 + len2);
    k -= in1 * n;
    in2 -= in1;
    if (k <= in2) {
      cout << len2 + k << endl;
      continue;
    }
    long long ans = step2 + (k - in2) * 2;
    if (in2 * n <= k)
      ans = min(ans, step2 * n + (k - in2 * n) * 2);
    else {
      long long m = k / in2;
      if (k % in2) {
        ans = min(ans, step2 * m + len2 + k % in2);
        ans = min(ans, step2 * m + (k % in2) * 2);
      } else
        ans = min(ans, step2 * m);
    }
    cout << ans << endl;
  }
  return 0;
}
