#include <bits/stdc++.h>
using namespace std;
struct quad {
  long long a1, a2, b1, b2;
};
bool cmp(quad q1, quad q2) { return (q1.b1 - q1.a2) <= (q2.b1 - q2.a2); }
void solve() {
  long long n, k;
  cin >> n >> k;
  string err;
  err += to_string(n) + "," + to_string(k) + ",";
  long long curr = 0, cnt = 0;
  long long flag = 0;
  vector<std::pair<long long, long long> > v1, v2;
  long long x, y;
  cin >> x >> y;
  err += to_string(x) + "," + to_string(y) + ",";
  for (long long i = 0; i < (n); ++i) {
    v1.push_back({x, y});
  }
  cin >> x >> y;
  err += to_string(x) + "," + to_string(y);
  for (long long i = 0; i < (n); ++i) v2.push_back({x, y});
  for (long long i = 0; i < (n); ++i) {
    if (v1[i].second <= v2[i].first || v2[i].second <= v1[i].first) continue;
    curr += min(v1[i].second, v2[i].second) - max(v1[i].first, v2[i].first);
  }
  if (curr >= k) {
    cout << 0 << "\n";
    return;
  }
  for (long long i = 0; i < (n); ++i) {
    if (curr >= k) break;
    if (v1[i].second <= v2[i].first || v2[i].second <= v1[i].first) continue;
    long long rtmin = min(v1[i].second, v2[i].second);
    long long rtmax = max(v1[i].second, v2[i].second);
    long long ltmin = max(v1[i].first, v2[i].first);
    long long ltmax = min(v1[i].first, v2[i].first);
    long long reqd = k - curr;
    long long pot = rtmax - rtmin + ltmin - ltmax;
    curr += min(reqd, pot);
    cnt += min(reqd, pot);
    v1[i].first = ltmax;
    v2[i].first = ltmax;
    v1[i].second = rtmax;
    v2[i].second = rtmax;
    flag = 1;
  }
  if (curr >= k) {
    if (cnt == -1) {
      cout << err << ":1"
           << "\n";
      return;
    }
    cout << cnt << "\n";
    return;
  }
  vector<quad> v;
  for (long long i = 0; i < (n); ++i) {
    if (v1[i].first == v2[i].first && v1[i].second == v2[i].second) {
      continue;
    }
    if (v1[i].second <= v2[i].first)
      v.push_back({v1[i].first, v1[i].second, v2[i].first, v2[i].second});
    else
      v.push_back({v2[i].first, v2[i].second, v1[i].first, v1[i].second});
  }
  for (long long i = 0; i < ((long long)v.size()); ++i) {
    if (curr >= k) break;
    long long reqd = k - curr;
    long long pot = v[i].b2 - v[i].a1;
    if (v[i].b1 - v[i].a2 + min(reqd, pot) > 2 * min(reqd, pot) && flag) {
      cnt += 2 * min(reqd, pot);
      curr += min(reqd, pot);
      flag = 1;
    } else {
      cnt += v[i].b1 - v[i].a2;
      curr += min(reqd, pot);
      cnt += min(reqd, pot);
      flag = 1;
    }
  }
  if (curr >= k) {
    if (cnt == -1) {
      cout << err << ":2"
           << "\n";
      return;
    }
    cout << cnt << "\n";
    return;
  }
  cnt = cnt + 2 * (k - curr);
  if (cnt == -1) {
    cout << err << ":3"
         << "\n";
    return;
  }
  cout << cnt << "\n";
}
signed main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
