#include <bits/stdc++.h>
using namespace std;
long long t, n, k, la, ra, lb, rb, dis, eas, ans;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n >> k >> la >> ra >> lb >> rb;
    eas = max(ra, rb) - min(la, lb);
    if (ra <= lb && rb >= la)
      dis = lb - ra;
    else if (rb <= la && ra >= lb)
      dis = la - rb;
    else {
      dis = 0;
      k -= (ra - la + rb - lb - (max(ra, rb) - min(la, lb))) * n;
      eas = ((max(ra, rb) - min(la, lb)) * 2 - (ra - la + rb - lb));
    }
    if (k <= 0) {
      cout << 0 << endl;
      continue;
    }
    if (k > n * eas) {
      cout << n * (dis + eas) + 2 * (k - n * eas) << endl;
      continue;
    }
    if (eas == 0) {
      cout << 2 * k << endl;
      continue;
    }
    long long nreq = k / eas;
    if (nreq == 0) {
      cout << dis + k << endl;
      continue;
    }
    ans = nreq * (dis + eas);
    if (k - eas * nreq <= dis)
      ans += 2 * (k - eas * nreq);
    else {
      ans += dis;
      ans += (k - eas * nreq);
    }
    cout << ans << endl;
  }
}
