#include <bits/stdc++.h>
using namespace std;
int inside(long long l, long long r, long long x) { return l <= x && x <= r; }
int dist(long long l, long long r) { return abs(l - r); }
int main() {
  int t;
  cin >> t;
  for (int cas = 0; cas < t; ++cas) {
    long long n, k;
    cin >> n >> k;
    long long l1, r1;
    cin >> l1 >> r1;
    long long l2, r2;
    cin >> l2 >> r2;
    long long a1 = 0, a2 = 0;
    long long add = 0, add2 = 0;
    if (inside(l1, r1, l2) || inside(l1, r1, r2) || inside(l2, r2, l1) ||
        inside(l2, r2, r1)) {
      add = n * 1ll * dist(max(l1, l2), min(r1, r2));
      add2 = n * 1ll * dist(min(l1, l2), max(r1, r2));
      if (k <= add) {
        printf("0\n");
      } else if (add < k && k <= add2) {
        printf("%lld\n", k - add);
      } else {
        printf("%lld\n", add2 - add + 2ll * (k - add2));
      }
    } else {
      a1 = min(dist(l2, r1), dist(l1, r2));
      a2 = max(dist(l2, r1), dist(l1, r2));
      if (k == 0) {
        printf("0\n");
      } else if (k <= a2) {
        printf("%lld\n", a1 + k);
      } else {
        long long taken = k / a2;
        taken = min(taken, n);
        k = k - taken * a2;
        if (taken < n) {
          if (k <= a1) {
            printf("%lld\n", taken * (a1 + a2) + 2ll * k);
          } else if (k < a2) {
            printf("%lld\n", taken * (a1 + a2) + a1 + k);
          } else {
            assert(0);
          }
        } else {
          printf("%lld\n", taken * (a1 + a2) + 2ll * k);
        }
      }
    }
  }
}
