#include <bits/stdc++.h>
using namespace std;
long long t;
int main() {
  cin >> t;
  while (t--) {
    long long n, k;
    long long sol = 0;
    cin >> n >> k;
    long long l1, r1, l2, r2;
    cin >> l1 >> r1 >> l2 >> r2;
    if (l1 > l2) swap(l1, l2), swap(r1, r2);
    long long ec = max(0LL, l2 - r1);
    long long mg = max(r2, r1) - l1 - max(0LL, (min(r1, r2) - l2));
    long long e = 0;
    if (ec == 0)
      e = n, k = max(0LL, k - n * (min(r2, r1) - l2)), n = 0;
    else
      sol += ec, e = 1, n--;
    if (mg <= ec) {
      if (k <= mg)
        sol += k, k = 0;
      else
        sol += mg, k -= mg;
      sol += 2 * k;
      k = 0;
    }
    while (k) {
      if (e) {
        if (k <= mg)
          sol += k, k = 0;
        else
          sol += mg, k -= mg, e--;
      } else {
        if (k < mg && 2 * k < (ec + k)) break;
        if (!n)
          break;
        else {
          e++;
          n--;
          sol += ec;
        }
      }
    }
    if (k) sol += 2 * k, k = 0;
    cout << sol << "\n";
  }
  return 0;
}
