#include <bits/stdc++.h>
using namespace std;
inline void Boost() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int main() {
  Boost();
  int T;
  cin >> T;
  while (T--) {
    long long n, k, l1, r1, l2, r2;
    cin >> n >> k >> l1 >> r1 >> l2 >> r2;
    long long ans = 1e18;
    if (max(l1, l2) <= min(r1, r2)) {
      long long rem = max(0LL, k - n * (min(r1, r2) - max(l1, l2)));
      long long maxPos = n * (abs(l1 - l2) + abs(r1 - r2));
      ans = min(rem, maxPos) + max(0LL, rem - maxPos) * 2;
    } else {
      long long invest = max(l1, l2) - min(r1, r2);
      for (long long cnt = 1; cnt <= n; cnt++) {
        long long curAns = invest * cnt;
        long long maxPos = (max(r1, r2) - min(l1, l2)) * cnt;
        curAns += min(k, maxPos) + max(0LL, k - maxPos) * 2;
        ans = min(ans, curAns);
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
