#include <bits/stdc++.h>
using namespace std;
void setup();
void sieve();
long long pow();
long long powm();
bool isprime();
long long modInverse();
vector<long long> prime;
static const long long MOD[2] = {998244353, 1000000007};
void solve() {
  long long n, k;
  cin >> n >> k;
  long long l1, r1, l2, r2;
  cin >> l1 >> r1 >> l2 >> r2;
  long long ans = 0;
  long long I = 0;
  if (l2 < l1) {
    swap(l1, l2);
    swap(r2, r1);
  }
  if (l2 <= r1) {
    I = n * (min(r1, r2) - l2);
    k -= I;
    long long steps = l2 - l1 + abs(r2 - r1);
    for (long long i = 1; i <= n and k > 0; i++) {
      long long available_or_required = min(k, steps);
      k -= available_or_required;
      ans += available_or_required;
    }
    ans += max(0LL, 2 * k);
  } else {
    ans = l2 - r1;
    long long available_or_required = min(k, r2 - l1);
    ans += available_or_required;
    k -= available_or_required;
    for (long long i = 2; i <= n and k > 0; i++) {
      long long merge_req = l2 - r1;
      available_or_required = min(k, r2 - l1);
      if (available_or_required + merge_req <= 2 * available_or_required) {
        k -= available_or_required;
        ans += available_or_required + merge_req;
      } else {
        ans += 2 * k;
        k = 0;
        break;
      }
    }
    ans += max(0LL, 2 * k);
  }
  cout << ans;
  cout << "\n";
}
signed main() {
  setup();
  int number_of_testcases = 1;
  cin >> number_of_testcases;
  while (number_of_testcases--) solve();
}
void setup() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}
void sieve(long long n) {
  prime.resize(n + 5, 0);
  for (long long i = 2; i <= n; i++) {
    if (not prime[i]) {
      prime[i] = i;
      for (long long j = i * i; j <= n; j += i)
        if (not prime[j]) prime[j] = i;
    }
  }
}
long long pow(long long b, long long e) {
  if (e == 0)
    return 1;
  else if (e % 2 == 0) {
    long long a = pow(b, e / 2);
    return a * a;
  } else {
    long long a = pow(b, e / 2);
    return b * a * a;
  }
}
long long powm(long long x, long long y, long long m) {
  x = x % m;
  long long res = 1;
  while (y) {
    if (y & 1) res = res * x;
    res %= m;
    y = y >> 1;
    x = x * x;
    x %= m;
  }
  return res;
}
long long gcd(long long a, long long b) {
  if (a < b)
    return gcd(b, a);
  else if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
bool isprime(long long n) {
  for (long long i = 2; i * i <= n; i++)
    if (n % i == 0) return 0;
  return 1;
}
long long modInverse(long long a, long long m) { return powm(a, m - 2, m); }
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (T e : v) os << e << ", ";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
  for (T e : v) os << e << ", ";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const multiset<T>& v) {
  for (T e : v) os << e << ", ";
  return os;
}
template <typename T, typename Y>
ostream& operator<<(ostream& os, const pair<T, Y>& v) {
  os << '{' << v.first << ", " << v.second << "}";
  return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v) {
  for (auto it : v) os << "{" << it.first << ", " << it.second << "}, ";
  return os;
}
