#include <bits/stdc++.h>
using namespace std;
void fun() {
  long long int n, k, a, b, c, d;
  cin >> n >> k >> a >> b >> c >> d;
  if (b < c) {
    long long int s1 = (c - a) + (d - b);
    long long int s2 = d - a;
    if (k < s2) {
      cout << (c + k - b) << "\n";
      return;
    }
    long long int p = k / s2;
    long long int r = k % s2;
    if (p >= n) {
      cout << (n * s1) + 2 * (k - n * s2) << "\n";
      return;
    }
    {
      cout << ((p * s1) + min((r + c - b), 2 * r)) << "\n";
      return;
    }
  } else if (d < a) {
    long long int s1 = (a - c) + (b - d);
    long long int s2 = b - c;
    if (k < s2) {
      cout << (a + k - d) << "\n";
      return;
    }
    long long int p = k / s2;
    long long int r = k % s2;
    if (p >= n) {
      cout << (n * s1) + 2 * (k - n * s2) << "\n";
      return;
    }
    {
      cout << ((p * s1) + min((r + a - d), 2 * r)) << "\n";
      return;
    }
  } else if ((a >= c) && (b <= d)) {
    if (n * (b - a) >= k) {
      cout << 0 << "\n";
      return;
    } else if (n * (d - c) >= k) {
      k = k - n * (b - a);
      cout << k << "\n";
    } else {
      k = k - n * (d - c);
      long long int p = (d - b + a - c) * n;
      p = p + (2 * k);
      cout << p << "\n";
    }
  } else if ((a <= c) && (b >= d)) {
    if (n * (d - c) >= k) {
      cout << 0 << "\n";
      return;
    } else if (n * (b - a) >= k) {
      k = k - n * (d - c);
      cout << k << "\n";
    } else {
      k = k - n * (b - a);
      long long int p = (b - d + c - a) * n;
      p = p + (2 * k);
      cout << p << "\n";
    }
  } else if ((a <= c) && (b <= d)) {
    if (n * (b - c) >= k) {
      cout << 0 << "\n";
      return;
    } else if (n * (d - a) >= k) {
      k = k - n * (b - c);
      cout << k << "\n";
    } else {
      k = k - n * (d - a);
      long long int p = (d - b + c - a) * n;
      p = p + (2 * k);
      cout << p << "\n";
    }
  } else if ((a >= c) && (b >= d)) {
    if (n * (d - a) >= k) {
      cout << 0 << "\n";
      return;
    } else if (n * (b - c) >= k) {
      k = k - n * (d - a);
      cout << k << "\n";
    } else {
      k = k - n * (b - c);
      long long int p = (b - d + a - c) * n;
      p = p + (2 * k);
      cout << p << "\n";
    }
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long int n;
  cin >> n;
  while (n--) fun();
  return 0;
}
