#include <bits/stdc++.h>
using namespace std;
int a, b, c, d, n, l, r;
long long k, x, sum, ans;
int main() {
  int tt = 0;
  scanf("%d", &tt);
  while (tt--) {
    scanf("%d%lld", &n, &k);
    ans = 1ll << 60;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    if (a > c) {
      swap(a, c);
      swap(b, d);
    }
    if (c < b) {
      k -= (min(b, d) - c) * (long long)n;
      if (k <= 0) {
        puts("0");
        continue;
      }
    }
    l = min(a, c);
    r = max(b, d);
    for (int i = 1; i <= n; i++) {
      if (b < c) {
        sum = (c - b) * (long long)i;
        x = r - l;
      } else {
        sum = 0;
        x = r - l - (min(b, d) - c);
      }
      x *= i;
      if (x >= k) {
        sum += k;
      } else {
        sum += k * 2 - x;
      }
      ans = min(ans, sum);
    }
    printf("%lld\n", ans);
  }
  return 0;
}
