#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
long long n, k, z, a[N];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, k, l1, r1, l2, r2;
    cin >> n >> k >> l1 >> r1 >> l2 >> r2;
    if (l1 > l2 || (l1 == l2 && r1 > r2)) swap(l1, l2), swap(r1, r2);
    if (l2 <= r1 && r2 >= r1) {
      long long kol = r2 - l1 - (r1 - l2);
      k -= (r1 - l2) * n;
      if (k <= 0)
        cout << "0\n";
      else if (kol * n >= k)
        cout << k << "\n";
      else
        cout << kol * n + (k - kol * n) * 2 << "\n";
    } else if (l2 <= r1 && r2 <= r1) {
      k -= (r2 - l2) * n;
      long long kol = r1 - l1 - (r2 - l2);
      if (k <= 0)
        cout << "0\n";
      else if (kol * n >= k)
        cout << k << "\n";
      else
        cout << kol * n + (k - kol * n) * 2 << "\n";
    } else {
      long long ans = 1e18;
      for (long long kol = 1; kol <= n; kol++) {
        long long t = (l2 - r1) * kol;
        if ((r2 - l1) * kol >= k)
          ans = min(ans, t + k);
        else {
          long long add = (r2 - l1) * kol;
          ans = min(ans, t + add + 2 * (k - add));
        }
      }
      cout << ans << "\n";
    }
  }
  return 0;
}
