#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    long long n, k;
    cin >> n >> k;
    pair<int, int> aa, bb;
    cin >> aa.first >> aa.second >> bb.first >> bb.second;
    if (k == 0) {
      cout << 0 << '\n';
      continue;
    }
    if (aa.first > bb.first) swap(aa, bb);
    int dist = bb.first - aa.second;
    long long ans = 0;
    if (dist < 0) {
      long long len = max(aa.second, bb.second) - aa.first;
      long long rng = min(aa.second, bb.second) - bb.first;
      if (k > n * rng) {
        k -= n * rng;
        long long add = len - rng;
        long long cost = min(k, add * n);
        ans += cost;
        k -= cost;
        ans += 2 * k;
      }
    } else {
      long long len = bb.second - aa.first;
      if (len == 0) {
        ans += 2 * k;
      } else if (k < len) {
        ans += dist + k;
      } else {
        long long seg = min(n, k / len);
        ans += seg * (dist + len);
        k -= seg * len;
        if (seg < n)
          ans += min(dist + k, 2 * k);
        else
          ans += 2 * k;
      }
    }
    cout << ans << '\n';
  }
}
