#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long bin(long long a, long long b, long long mod) {
  if (b == 0) return 1;
  if (b & 1) return (a * bin((a * a) % mod, b / 2, mod)) % mod;
  return (1 * bin((a * a) % mod, b / 2, mod)) % mod;
}
void I_m_Beast() {
  long long n, k;
  cin >> n >> k;
  long long a, b, c, d;
  cin >> a >> b;
  cin >> c >> d;
  long long ans = 0;
  if (a > c) {
    swap(a, c);
    swap(b, d);
  }
  if (b > c) {
    if (d <= b) {
      swap(b, d);
    }
    long long x = b - c;
    if (x * n >= k)
      cout << "0\n";
    else {
      k -= x * n;
      long long cost1 = (c - a) + (d - b);
      long long val = (d - a) - (b - c);
      if (val == 0) {
        cout << 2 * k << "\n";
        return;
      }
      long long num_seg = ceil((k * 1.0) / val);
      if (num_seg <= n) {
        ans += (k / val) * cost1;
        k = k % val;
        ans += k;
        cout << ans << "\n";
      } else {
        ans += n * cost1;
        k -= n * val;
        ans += k * 2;
        cout << ans << "\n";
      }
    }
  } else {
    long long cost1 = c - b;
    long long val = d - a;
    cost1 += d - a;
    if (val == 0) {
      cout << 2 * k << "\n";
      return;
    }
    long long num_seg = ceil((k * 1.0) / val);
    long long k1 = k;
    if (num_seg <= n) {
      ans = (k / val) * cost1;
      k = k % val;
      if (k1 / val > 0)
        ans += min(c - b + k, 2 * k);
      else
        ans += (c - b + k);
      cout << ans << "\n";
    } else {
      ans = n * cost1;
      k -= n * val;
      ans += k * 2;
      cout << ans << "\n";
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    I_m_Beast();
  }
  return 0;
}
