#include <bits/stdc++.h>
using namespace std;
long double eps = (long double)1 / 1e6;
long long inf = LLONG_MAX, mod1 = 1e9 + 7, mod2 = 998244353;
long long sqr(long long a) { return a * a; }
long long qb(long long a) { return a * a * a; }
long long gcd(long long a, long long b) { return !a ? b : gcd(b % a, a); }
long long binpow(long long a, long long b, long long mod) {
  return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod
                    : sqr(binpow(a, b / 2, mod)) % mod)
           : 1;
}
long long binmult(long long a, long long b, long long mod) {
  return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod
                    : (2 * binmult(a, b / 2, mod)) % mod)
           : 0;
}
int main() {
  cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0);
  long long q, n, k, i, bz, nd, l1, r1, l2, r2, s, z, gl, gr, ans;
  cin >> q;
  while (q--) {
    cin >> n >> k >> l1 >> r1 >> l2 >> r2;
    if (l1 > l2) swap(l1, l2), swap(r1, r2);
    s = bz = max((long long)0, min(r1, r2) - l2);
    s *= n;
    nd = max((long long)0, l2 - r1);
    if (s >= k) {
      cout << "0\n";
      continue;
    }
    ans = 0;
    z = l2 - l1 + abs(r2 - r1);
    gl = l1, gr = max(r1, r2);
    for (i = 1; i <= n; i++) {
      if (s + (gr - gl - bz) < k)
        s += (gr - gl - bz), ans += z;
      else {
        if (i > 1)
          ans += min(nd + k - s, 2 * (k - s));
        else
          ans += nd + k - s;
        break;
      }
    }
    if (i <= n)
      cout << ans << '\n';
    else
      cout << ans + 2 * (k - s) << '\n';
  }
  return 0;
}
