#include <bits/stdc++.h>
using namespace std;
long long int n, k, l1, l2, r1, r2;
long long int func(long long int x) {
  if (r1 >= l2) {
    long long int y = min(r1, r2) - l2;
    long long int sum = y * n, ext = max(r1, r2) - l1 - y;
    long long int temp = min(ext * n, x);
    sum += temp;
    x -= temp;
    x /= 2;
    sum += x;
    return sum;
  } else {
    long long int req = l2 - r1, sum = 0;
    for (long long int i = 1; i <= n; i++)
      if (x >= req * i) {
        long long int temp = x - req * i;
        long long int ext = min(temp, i * (max(r1, r2) - l1));
        temp -= min(temp, i * (max(r1, r2) - l1));
        temp /= 2;
        ext += temp;
        sum = max(sum, ext);
      }
    return sum;
  }
}
void solve() {
  cin >> n >> k >> l1 >> r1 >> l2 >> r2;
  if (l1 > l2) {
    swap(l1, l2);
    swap(r1, r2);
  }
  long long int l = 0, r = pow(10, 16);
  while (l <= r) {
    long long int m = (l + r) / 2;
    if (func(m) >= k)
      r = m - 1;
    else
      l = m + 1;
  }
  cout << l << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  clock_t z = clock();
  long long int qc = 1;
  cin >> qc;
  for (long long int i = 1; i <= qc; i++) {
    solve();
  }
  fprintf(stderr, "Total Time:%.4Lf\n",
          (long double)(clock() - z) / CLOCKS_PER_SEC),
      fflush(stderr);
}
