#include <bits/stdc++.h>
using namespace std;
int T;
int n, k, l1, r1, l2, r2;
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> T;
  while (T--) {
    cin >> n >> k;
    cin >> l1 >> r1;
    cin >> l2 >> r2;
    if (k == 0) {
      cout << 0 << endl;
      continue;
    }
    if (l1 > l2) {
      swap(l1, l2);
      swap(r1, r2);
    }
    if (l2 <= r1) {
      if (r2 <= r1) {
        long long tmp = r2 - l2;
        tmp *= n;
        if (tmp >= k) {
          cout << 0 << endl;
        } else {
          long long ans = 0;
          long long need = k - tmp;
          long long onestep = r1 - r2 + l2 - l1;
          if (onestep != 0) {
            long long needI = need / onestep + (need % onestep != 0);
            if (needI > n) {
              need -= n * onestep;
              ans += n * onestep;
            } else {
              ans += need;
              need = 0;
            }
          }
          ans += need * 2;
          cout << ans << endl;
        }
      } else {
        long long tmp = r1 - l2;
        tmp *= n;
        if (tmp >= k) {
          cout << 0 << endl;
        } else {
          long long ans = 0;
          long long need = k - tmp;
          long long onestep = r2 - r1 + l2 - l1;
          if (onestep != 0) {
            long long needI = need / onestep + (need % onestep != 0);
            if (needI > n) {
              ans += n * onestep;
              need -= n * onestep;
            } else {
              ans += need;
              need = 0;
            }
          }
          ans += need * 2;
          cout << ans << endl;
        }
      }
    } else {
      long long need = k;
      long long gap = l2 - r1;
      long long maxl = r2 - l1;
      if (need <= maxl) {
        cout << gap + need << endl;
      } else {
        long long ans = 0;
        ans += maxl + gap;
        need -= maxl;
        n--;
        long long cost1 = maxl * 2;
        long long cost2 = maxl + gap;
        if (cost2 < cost1) {
          long long needI = need / maxl;
          needI = min(needI, 1LL * n);
          need -= needI * maxl;
          ans += cost2 * needI;
          n -= needI;
        }
        if (need >= maxl || n == 0) {
          ans += need * 2;
        } else {
          cost1 = need * 2;
          cost2 = need + gap;
          ans += min(cost1, cost2);
        }
        cout << ans << endl;
      }
    }
  }
  return 0;
}
