#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 10;
long long t;
long long n, k;
long long l1, r1, l2, r2;
signed main() {
  scanf("%lld", &t);
  while (t--) {
    scanf("%lld%lld", &n, &k);
    scanf("%lld%lld%lld%lld", &l1, &r1, &l2, &r2);
    if (l1 > l2) swap(l1, l2), swap(r1, r2);
    if (l1 <= l2 && r1 >= r2) {
      k -= (r2 - l2) * n;
      if (k <= 0) {
        printf("0\n");
        continue;
      }
      long long t = l2 - l1 + r1 - r2;
      t *= n;
      if (k <= t) {
        printf("%lld\n", k);
        if (k == 10126) printf("I am here!\n");
        continue;
      }
      k -= t;
      printf("%lld\n", 2 * k + t);
      if (2 * k + t == 10126) printf("I am not here!\n");
      continue;
    }
    if (r1 >= l2) {
      k -= (r1 - l2) * n;
      if (k <= 0) {
        printf("0\n");
        continue;
      }
      long long t = (l2 - l1) + (r2 - r1);
      t *= n;
      if (k <= t) {
        printf("%lld\n", k);
        continue;
      }
      k -= t;
      printf("%lld\n", 2 * k + t);
      continue;
    }
    long long cost = l2 - r1, val = r2 - l1, ans;
    if (k <= val) {
      printf("%lld\n", cost + k);
      continue;
    }
    ans = val + cost, k -= val;
    if (val <= cost) {
      printf("%lld\n", ans + 2 * k);
      continue;
    }
    long long ts = k / val, res = k % val;
    if (ts >= (n - 1)) {
      ans = n * (val + cost);
      res = k - (n - 1) * val;
      ans += res * 2;
      printf("%lld\n", ans);
      if (ans == 10126) printf("fuck this world!\n");
      continue;
    } else {
      ans += ts * (val + cost);
      ans += min(cost + res, res * 2);
      printf("%lld\n", ans);
    }
  }
}
