#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, k;
  scanf("%I64d%I64d", &n, &k);
  long long l1, r1, l2, r2;
  scanf("%I64d%I64d%I64d%I64d", &l1, &r1, &l2, &r2);
  if (l1 > l2) {
    swap(l1, l2);
    swap(r1, r2);
  }
  if ((min(r1, r2) - l2) * n >= k) {
    printf("0\n");
    return;
  }
  if (l2 <= r1) {
    k -= (min(r1, r2) - l2) * n;
    long long x = n * (abs(r1 - r2) + abs(l1 - l2));
    if (k <= x)
      printf("%I64d\n", k);
    else
      printf("%I64d\n", x + (k - x) * 2);
    return;
  }
  long long init_time = l2 - r1;
  long long get = r2 - l1;
  if (k <= get) {
    printf("%I64d\n", init_time + k);
    return;
  }
  k -= get;
  long long time = init_time + get;
  n--;
  if (get * n <= k) {
    k -= get * n;
    time += n * (init_time + get);
    printf("%I64d\n", time + 2 * k);
    return;
  }
  long long tmp = k / get;
  tmp = min(tmp, n);
  k -= tmp * get;
  time += tmp * (init_time + get);
  long long cost = min(k * 2, init_time + k);
  printf("%I64d\n", time + cost);
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) solve();
  return 0;
}
