#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    int l1, r1, l2, r2;
    cin >> l1 >> r1 >> l2 >> r2;
    if (l1 > l2) swap(l1, l2), swap(r1, r2);
    int zero = max(0, l2 - r1);
    int um = abs(l1 - l2) + abs(r1 - r2) - zero;
    int ini = max(0, min(r1, r2) - l2);
    k -= n * ini;
    if (k <= 0) {
      cout << 0 << '\n';
      continue;
    }
    long long anss = LINF;
    long long k2 = k;
    for (long long i = 1; i <= n; i++) {
      k = k2;
      long long ans = i * zero;
      if (k <= i * um) {
        ans += k;
        anss = min(anss, ans);
        continue;
      }
      ans += i * um;
      k -= i * um;
      ans += 2 * k;
      anss = min(anss, ans);
    }
    cout << anss << '\n';
  }
  exit(0);
}
