#include <bits/stdc++.h>
using namespace std;
const long long sz = 2e5 + 10;
pair<long long, long long> a[sz], b[sz];
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, k;
    scanf("%lld", &n), scanf("%lld", &k);
    long long l1, r1;
    scanf("%lld", &l1), scanf("%lld", &r1);
    long long l2, r2;
    scanf("%lld", &l2), scanf("%lld", &r2);
    if (l1 > l2) {
      swap(l1, l2);
      swap(r1, r2);
    }
    for (long long i = 1; i <= n; ++i) a[i] = make_pair(l1, r1);
    for (long long i = 1; i <= n; ++i) b[i] = make_pair(l2, r2);
    long long extra = max(0LL, l2 - r1);
    long long ans = (1LL << 62);
    for (long long i = 1; i <= n; ++i) {
      long long cst = extra * i;
      long long lmax = max(l1, l2), rmin = min(r1, r2);
      long long seg = max(0LL, rmin - lmax), now = seg * i;
      if (now >= k) {
        ans = min(ans, cst);
        continue;
      }
      long long lmin = min(l1, l2), rmax = max(r1, r2);
      long long full = (rmax - lmin) * i;
      if (full >= k) {
        ans = min(ans, cst + (k - now));
        continue;
      }
      cst += (full - now);
      ans = min(ans, cst + 2 * (k - full));
    }
    printf("%lld\n", ans);
  }
  return 0;
}
