#include <bits/stdc++.h>
using namespace std;
int t;
long long n, k;
long long l1, r1;
long long l2, r2;
int main() {
  scanf("%d", &t);
  while (t--) {
    long long res = (long long)(1e18);
    scanf("%lld%lld", &n, &k);
    scanf("%lld%lld%lld%lld", &l1, &r1, &l2, &r2);
    long long init_int = 0, dist = 0;
    int s = min(r1, r2) - max(l1, l2);
    if (s >= 0) {
      init_int = s * n;
      dist = 0;
    } else {
      init_int = 0;
      dist = -s;
    }
    if (init_int >= k) {
      printf("0\n");
      continue;
    }
    if (dist == 0) {
      if (n * (max(r1, r2) - min(l1, l2)) >= k)
        res = k - init_int;
      else
        res = n * (max(r1, r2) - min(l1, l2) - s) +
              (k - init_int - n * (max(r1, r2) - min(l1, l2) - s)) * 2;
    } else {
      long long res_temp;
      for (int i = 1; i <= n; i++) {
        if (i * (max(r1, r2) - min(l1, l2)) >= k)
          res_temp = i * dist + k;
        else
          res_temp = i * dist + i * (max(r1, r2) - min(l1, l2)) +
                     2 * (k - i * (max(r1, r2) - min(l1, l2)));
        res = min(res, res_temp);
      }
    }
    printf("%lld\n", res);
  }
  return 0;
}
