#include <bits/stdc++.h>
using namespace std;
const long long zero = 0;
const long long INF = 3000000000000000000;
const int inINF = 1000000000;
const long long MOD = 1000000007;
const long long MOD2 = 998244353;
void Yes() { printf("Yes\n"); }
void No() { printf("No\n"); }
void YES() { printf("YES\n"); }
void NO() { printf("NO\n"); }
long long n, k;
long long l1, r1;
long long l2, r2;
void solve() {
  cin >> n >> k >> l1 >> r1 >> l2 >> r2;
  long long tmp;
  long long ret = INF;
  long long M;
  if (r2 < l1) {
    tmp = l1;
    l1 = l2;
    l2 = tmp;
    tmp = r1;
    r1 = r2;
    r2 = tmp;
  }
  if (r1 < l2) {
    for (long long i = 1; i < n + 1; i++) {
      tmp = i * (l2 - r1);
      M = r2 - l1;
      if (i * M >= k) {
        tmp += k;
      } else {
        tmp += i * M + 2 * (k - i * M);
      }
      ret = min(tmp, ret);
    }
  } else {
    M = max(r1, r2) - min(l1, l2);
    long long L = min(r1, r2) - max(l1, l2);
    if (n * M >= k) {
      ret = max(k - n * L, zero);
    } else {
      ret = max(n * (M - L) + 2 * (k - n * M), zero);
    }
  }
  printf("%lld\n", ret);
}
int main() {
  long long t;
  cin >> t;
  for (long long i = 0; i < t; i++) {
    solve();
  }
}
