#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
int cc[10];
int nxt[maxn][10];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    long long l1, r1, l2, r2;
    cin >> l1 >> r1 >> l2 >> r2;
    long long mil = min(l1, l2), mar = max(r1, r2), mal = max(l1, l2),
              mir = min(r1, r2);
    long long tt = mar - mil;
    long long cc = mal - mil + mar - mir;
    long long cp = max(0LL, mal - mir);
    long long tp = max(mir - mal, 0LL);
    long long ans = 1e18;
    for (int i = 1; i <= n; i++) {
      long long kk = n * tp + i * (tt - tp);
      if (kk >= k) {
        long long cost = cc * (i - 1);
        kk = k - (n * tp + (i - 1) * (tt - tp));
        if (kk <= 0)
          ans = min(ans, (i - 1) * cc);
        else {
          long long y = (i - 1) * cc;
          y += cp + kk;
          ans = min(ans, y);
        }
      } else {
        kk = k - kk;
        ans = min(ans, i * cc + kk * 2);
      }
    }
    cout << ans << '\n';
  }
}
