#include <bits/stdc++.h>
using namespace std;
int64_t n;
int64_t k;
pair<int64_t, int64_t> gora, dno;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  for (int testt = 1; testt <= t; ++testt) {
    cin >> n >> k;
    cin >> gora.first >> gora.second;
    cin >> dno.first >> dno.second;
    if (gora.first > dno.first) swap(gora, dno);
    int64_t way_touch = max(int64_t(0), dno.first - gora.second);
    int64_t meet = min(gora.second, dno.second) - dno.first;
    int64_t way_one_step = max(gora.second, dno.second) - gora.first;
    if (meet > 0) way_one_step -= meet;
    if (meet > 0) k -= meet * n;
    if (k <= 0) {
      cout << 0 << '\n';
      continue;
    }
    int64_t step = 0;
    if (way_touch >= way_one_step) {
      step = way_touch;
      step += min(k, way_one_step);
      k -= way_one_step;
      if (k > 0) {
        step += k * 2;
      }
    } else {
      int64_t combo = way_touch + way_one_step;
      int64_t cnt = k / way_one_step;
      if (cnt > n || (cnt == n && k % way_one_step > 0)) {
        step = combo * n;
        k -= way_one_step * n;
        step += k * 2;
      } else {
        step = combo * cnt;
        k %= way_one_step;
        if (k > 0) {
          int64_t val = way_touch + k;
          if (cnt > 0) val = min(val, 2 * k);
          step += val;
        }
      }
    }
    cout << step << '\n';
  }
}
