#include <bits/stdc++.h>
using namespace std;
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}
bool compare(const pair<int long long, int long long> &a,
             const pair<int long long, int long long> &b) {
  return a.second <= b.second;
}
int long long inline power(int long long a, int long long b, int long long p) {
  a %= p;
  int long long ans = 1;
  while (b > 0) {
    if (b & 1) ans = (ans * a) % p;
    a = (a * a) % p;
    b >>= 1;
  }
  return ans;
}
int long long inv(int long long n, int long long p) {
  return power(n, p - 2, p);
}
bool inline isPrime(int long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int long long i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
int long long gcd(int long long a, int long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void solve() {
  int long long n, m, i, j, k, l, r;
  cin >> n >> k;
  int long long x[2], y[2];
  cin >> x[0] >> y[0];
  cin >> x[1] >> y[1];
  int long long len = max(y[0], y[1]) - min(x[0], x[1]);
  int long long val = 2 * len - (y[1] - x[1]) - (y[0] - x[0]);
  int long long mx = 1e18;
  for (i = 1; i <= n; i++) {
    int long long tl = i * len;
    int long long tv = i * val;
    if (tl > k)
      tv -= tl - k;
    else
      tv += 2 * (k - tl);
    mx = min(mx, tv);
  }
  if (mx < 0)
    cout << "0\n";
  else
    cout << mx << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int long long t;
  cin >> t;
  while (t--) solve();
}
