#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int te;
  cin >> te;
  for (long long int w = 0; w < te; w++) {
    long long int n, k;
    cin >> n >> k;
    vector<pair<long long int, long long int> > v(2);
    cin >> v[0].first >> v[0].second >> v[1].first >> v[1].second;
    sort(v.begin(), v.end());
    long long int l1 = v[0].first, r1 = v[0].second, l2 = v[1].first,
                  r2 = v[1].second;
    if (r1 <= l2) {
      long long int mv = l2 - r1;
      long long int imp = r2 - l1;
      long long int ans = 0;
      long long int f = 0;
      for (long long int i = 0; i < n and k > 0; i++) {
        long long int steps = min(k, imp);
        long double avg = (steps + mv) / (long double)steps;
        if (avg < 2.0 or i == 0) {
          k -= steps;
          ans += mv + steps;
        } else {
          f = 1;
          break;
        }
      }
      ans += k * 2;
      cout << ans << endl;
    } else {
      long long int llier = min(r1, r2) - max(l1, l2);
      if (k <= n * 1LL * llier)
        cout << "0" << endl;
      else {
        k -= n * llier;
        long long int pot = abs(l1 - l2) + abs(r1 - r2);
        long long int ans = 0;
        for (long long int i = 0; i < n and k > 0; i++) {
          ans += min(k, pot);
          k -= min(k, pot);
        }
        ans += 2 * k;
        cout << ans << endl;
      }
    }
  }
}
