#include <bits/stdc++.h>
using namespace std;
const double pi = 3.141592653589;
const long long int zero = 0;
long long int mod = 998244353;
const long long int inf = 1e9;
const long long int inff = 9000000000000000000;
char al[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
               'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
char capital[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
                    'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
                    'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    long long int l1, r1, l2, r2, touch, ini, fin;
    cin >> l1 >> r1 >> l2 >> r2;
    ini = min(r1, r2) - max(l1, l2);
    ini = max(ini, zero);
    if (ini * n >= k) {
      cout << 0 << "\n";
      continue;
    }
    touch = max(l1, l2) - min(r1, r2);
    touch = max(touch, zero);
    fin = max(r1, r2) - min(l1, l2);
    if (fin == ini) {
      cout << (k - n * ini) * 2 << "\n";
      continue;
    }
    if (fin + (n - 1) * ini >= k) {
      cout << touch + k - n * ini << "\n";
      continue;
    }
    k -= (n - 1) * ini;
    k -= fin;
    long long int ans = touch + fin - ini;
    long long int complete = k / (fin - ini);
    if (complete * (fin - ini) * 2 >= complete * (touch + fin - ini)) {
      k = k % (fin - ini);
      if (complete < n - 1) {
        ans += complete * (touch + fin - ini);
        ans += min(2 * k, touch + k);
        cout << ans << "\n";
      } else {
        ans += (n - 1) * (touch + fin - ini);
        ans += (complete - (n - 1)) * 2 * (fin - ini);
        ans += k * 2;
        cout << ans << "\n";
      }
    } else {
      ans += complete * (fin - ini) * 2;
      ans += (k % (fin - ini)) * 2;
      cout << ans << "\n";
    }
  }
}
