#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
const long long inf = 3e10;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    long long l1, r1;
    cin >> l1 >> r1;
    long long l2, r2;
    cin >> l2 >> r2;
    if (l1 > l2) {
      swap(l1, l2);
      swap(r1, r2);
    }
    long long inter = max(min(r1, r2) - l2, 0LL);
    k -= n * inter;
    if (k <= 0) {
      cout << 0 << "\n";
      continue;
    }
    long long gap = max(0LL, l2 - r1);
    long long poss = max(r1, r2) - l1 - inter;
    long long best = inf;
    for (int i = 1; i <= n; i++) {
      long long cur = i * gap;
      long long k2 = k;
      if (k2 <= i * poss) {
        best = min(best, cur + k2);
      } else {
        k2 -= i * poss;
        cur += i * poss;
        cur += 2LL * k2;
        best = min(best, cur);
      }
    }
    cout << best << "\n";
  }
  return 0;
}
