#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
const long long INF = 1e18 + 9;
long long intersect(int l1, int r1, int l2, int r2) {
  int l = max(l1, l2);
  int r = min(r1, r2);
  return max(r - l + 1, 0);
}
void solve() {
  int n, k;
  cin >> n >> k;
  int l1, l2, r1, r2;
  cin >> l1 >> r1 >> l2 >> r2;
  int l = min(l1, l2);
  int r = max(r1, r2);
  long long cross = intersect(l1, r1, l2, r2);
  long long base = (cross == 0 ? 0 : cross - 1) * n;
  if (base >= k) {
    cout << 0 << "\n";
    return;
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (base >= k) break;
    long long mn = 0;
    long long rem = k - base;
    if (cross == 0) {
      if (r1 < l2)
        mn = (l2 - r1);
      else
        mn = (l1 - r2);
    }
    long long can_have = min((r - l) - cross + (cross > 0 ? 1 : 0), rem);
    long long cost1 = (i > 0 ? can_have * 2 : INF);
    long long cost2 = mn + can_have;
    if (cost1 <= cost2) {
      ans += rem * 2LL;
      base += rem;
      break;
    }
    ans += cost2;
    base += min(rem, can_have);
  }
  if (base < k) ans += (k - base) * 2LL;
  cout << ans << "\n";
}
int main() {
  fast();
  int t;
  cin >> t;
  while (t--) solve();
}
