#include <bits/stdc++.h>
using namespace std;
const long long M = (1e9) + 7;
const long long N = 1e6 + 5;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long tc = 1;
  cin >> tc;
  for (long long ti = 1; ti <= tc; ti++) {
    long long n, k;
    cin >> n >> k;
    long long a[2], b[2];
    for (long long i = 0; i < 2; i++) cin >> a[i];
    for (long long i = 0; i < 2; i++) cin >> b[i];
    long long ans = 0;
    long long l = max(a[0], b[0]);
    long long r = min(a[1], b[1]);
    long long have = max(0LL, r - l) * n;
    k = max(0LL, k - have);
    long long can = 0, cost = 0;
    if (l <= r) {
      can += l - min(a[0], b[0]);
      can += max(a[1], b[1]) - r;
      can *= n;
      long long now = min(can, k);
      ans += now;
      k = max(0LL, k - now);
      ans += (2LL * k);
    } else {
      cost = l - r;
      long long len = max(a[1], b[1]) - min(a[0], b[0]);
      ans += cost;
      ans += min(k, len);
      k -= min(k, len);
      for (long long i = 1; k && i < n; i++) {
        long long tans = cost + min(k, len);
        if (tans > 2LL * k) {
          ans += (2 * k);
          k = 0;
          continue;
        }
        ans += tans;
        k -= min(k, len);
      }
      ans += 2LL * k;
    }
    cout << ans << endl;
  }
  return 0;
}
