#include <bits/stdc++.h>
using namespace std;
const long long LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
bool p_comp_fs(const pair<long long, long long> p1,
               const pair<long long, long long> p2) {
  return p1.first < p2.first;
};
bool p_comp_fg(const pair<long long, long long> p1,
               const pair<long long, long long> p2) {
  return p1.first > p2.first;
};
bool p_comp_ss(const pair<long long, long long> p1,
               const pair<long long, long long> p2) {
  return p1.second < p2.second;
};
bool p_comp_sg(const pair<long long, long long> p1,
               const pair<long long, long long> p2) {
  return p1.second > p2.second;
};
template <typename T>
vector<T> uniquen(vector<T> vec) {
  sort(ALL(vec));
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;
}
inline long long popcnt(long long x) {
  return __builtin_popcountll((unsigned long long)x);
};
template <class T>
bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
bool bit(long long st, long long b) { return ((st >> b) & 1) == 1; }
void solve(long long l, long long r, long long N, long long K) {
  long long def = r - l;
  if (def * N >= K) {
    cout << K << endstr;
    return;
  } else {
    long long rem = K - def * N;
    cout << def * N + 2 * rem << endstr;
  }
}
int main(int argc, const char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long T;
  cin >> T;
  for (long long _ = 0; _ < T; _++) {
    long long N, K;
    cin >> N >> K;
    long long l1, r1;
    cin >> l1 >> r1;
    long long l2, r2;
    cin >> l2 >> r2;
    if (l1 > l2) {
      swap(l1, l2);
      swap(r1, r2);
    }
    if (l1 == r1 && l2 <= l1 && l1 <= r2) {
      solve(l2, r2, N, K);
      continue;
    } else if (l2 == r2 && l1 <= l2 && l2 <= r1) {
      solve(l1, r1, N, K);
      continue;
    }
    long long cur = 0;
    long long def = max(min(r1, r2) - l2, 0ll);
    cur += N * def;
    if (cur >= K) {
      cout << 0 << endstr;
      continue;
    }
    long long r = max(r1, r2);
    if (def == 0) {
      long long m = l2 - r1;
      long long ans = LINF;
      for (long long i = (1); i < N + 1; i++) {
        long long cost = m * i;
        if (K <= i * (r - l1)) {
          chmin(ans, cost + K);
        } else {
          long long rem = K - i * (r - l1);
          chmin(ans, cost + i * (r - l1) + 2 * rem);
        }
      }
      cout << ans << endstr;
    } else {
      if (K <= N * (r - l1)) {
        cout << K - def * N << endstr;
      } else {
        long long ans = N * (r - l1) - def * N;
        long long rem = K - N * (r - l1);
        cout << ans + 2 * rem << endstr;
      }
    }
  }
  return 0;
}
