#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const long long mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    long long l1, r1, l2, r2;
    cin >> l1 >> r1 >> l2 >> r2;
    long long x = 0, y = 0;
    if (max(l1, l2) > min(r1, r2)) {
      x = max(l1, l2) - min(r1, r2);
      y = max(r1, r2) - min(l1, l2);
    } else {
      k -= 1ll * n * (min(r1, r2) - max(l1, l2));
      x = 0;
      y = max(r1, r2) - min(l1, l2) - min(r1, r2) + max(l1, l2);
    }
    if (k <= 0) {
      cout << 0 << "\n";
      continue;
    }
    long long ans = 1e15;
    for (int i = 1; i <= n; i++) {
      long long xx = 1ll * x * i;
      long long yy = 1ll * y * i;
      if (yy < k) {
        xx += 2ll * (k - yy);
      }
      xx += min(yy, k);
      ans = min(ans, xx);
    }
    cout << ans << "\n";
  }
}
