#include <bits/stdc++.h>
using namespace std;
void shikhar7s(long long int cas) {
  long long int n, k, i;
  cin >> n >> k;
  long long int l, r, x, y, a, b, p, q, ans = 0, c, d,
                                        cost = 2000000000000000000;
  cin >> l >> r >> x >> y;
  c = max(l, x);
  d = min(r, y);
  long long int val = max(0ll, d - c);
  k -= (val * n);
  if (k <= 0) {
    cout << ans << "\n";
    return;
  }
  for (i = 0; i < n; i++) {
    if (l <= x) {
      a = l;
      b = r;
      p = x;
      q = y;
    } else {
      a = x;
      b = y;
      p = l;
      q = r;
    }
    if (d < c) {
      ans += (p - b);
      p = b;
    }
    if (abs(p - a) + abs(b - q) < k) {
      ans += (abs(p - a) + abs(b - q));
      k -= (abs(p - a) + abs(b - q));
    } else {
      ans += k;
      k = 0;
      break;
    }
    cost = min(cost, ans + (2 * k));
  }
  cost = min(cost, ans + (2 * k));
  cout << cost << "\n";
}
signed main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t = 1;
  cin >> t;
  long long int cas = 1;
  while (cas <= t) {
    shikhar7s(cas);
    cas++;
  }
  return 0;
}
