#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void solve() {
  long long int n, k;
  cin >> n >> k;
  long long int l1, r1, l2, r2;
  cin >> l1 >> r1 >> l2 >> r2;
  if (l1 > l2) {
    swap(l1, l2);
    swap(r1, r2);
  }
  if (r1 < l2) {
    long long int d = l2 - r1;
    long long int ans = -1;
    for (long long int i = 1; i <= n; i++) {
      long long int q = 0;
      long long now = 0;
      q += d * i;
      if (i * (r2 - l1) >= k) {
        q += k;
      } else {
        q += i * (r2 - l1);
        now = i * (r2 - l1);
        now = k - now;
        q += 2 * now;
      }
      if (ans == -1) ans = q;
      ans = min(ans, q);
    }
    cout << ans << endl;
    return;
  }
  if (l2 <= r1 && r2 > r1) {
    long long now = (r1 - l2) * n;
    if (now >= k) {
      cout << 0 << endl;
      return;
    }
    if (n * (r2 - l1) >= k) {
      cout << k - now << endl;
      return;
    } else {
      long long q = n * (l2 - l1) + n * (r2 - r1);
      now = k - n * (r2 - l1);
      q += now * 2;
      cout << q << endl;
    }
  }
  if (l2 <= r1 && r2 <= r1) {
    long long now = (r2 - l2) * n;
    if (now >= k) {
      cout << 0 << endl;
      return;
    }
    if (n * (r1 - l1) >= k) {
      cout << k - now << endl;
      return;
    } else {
      long long q = n * (r1 - r2) + n * (l2 - l1);
      now = k - n * (r1 - l1);
      q += now * 2;
      cout << q << endl;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t > 0) {
    t--;
    solve();
  }
}
