#include <bits/stdc++.h>
using namespace std;
long long t, n, k;
long long l1, r1, l2, r2;
signed main() {
  scanf("%lld", &t);
  while (t--) {
    long long ans = 1e10;
    scanf("%lld %lld", &n, &k);
    scanf("%lld %lld %lld %lld", &l1, &r1, &l2, &r2);
    if (max(l1, l2) > min(r1, r2)) {
      long long touch = max(l1, l2) - min(r1, r2);
      for (long long inv = 1; inv <= n; inv++) {
        long long currentAns = touch * inv;
        long long maxPossible = inv * (max(r1, r2) - min(l1, l2));
        currentAns += min(maxPossible, k) + max(0LL, (k - maxPossible)) * 2LL;
        ans = min(ans, currentAns);
      }
    } else {
      long long rem = max(0LL, k - n * (min(r1, r2) - max(l1, l2)));
      long long maxPossible = n * (abs(l2 - l1) + abs(r2 - r1));
      ans = min(rem, maxPossible) + max(0LL, rem - maxPossible) * 2;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
