#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
void solve() {
  long long n, k;
  pair<long long, long long> p1, p2;
  scanf("%lld%lld%lld%lld%lld%lld", &n, &k, &p1.first, &p1.second, &p2.first,
        &p2.second);
  long long ov = max(0LL, min(p1.second, p2.second) - max(p1.first, p2.first));
  if (ov * n >= k) {
    puts("0");
    return;
  }
  if (p1 > p2) swap(p1, p2);
  k -= ov * n;
  long long dist = max(0LL, p2.first - p1.second);
  long long ad = (max(p1.second, p2.second) - min(p1.first, p2.first)) - ov;
  long long ans = LLONG_MAX;
  for (long long i = 1; i <= n; ++i) {
    long long cost = (ad + dist) * i;
    long long rm = k - ad * i;
    if (rm >= 0)
      cost += rm * 2;
    else
      cost += rm;
    ans = min(ans, cost);
  }
  printf("%lld\n", ans);
}
signed main(void) {
  long long T = 1;
  scanf("%lld", &T);
  while (T--) solve();
  return 0;
}
