#include <bits/stdc++.h>
using namespace std;
long long t, n, k, al, ar, bl, br;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> t;
  while (t--) {
    cin >> n >> k >> al >> ar >> bl >> br;
    if (min(ar, br) >= max(al, bl)) {
      k -= (min(ar, br) - max(al, bl)) * n;
    }
    if (k <= 0) {
      cout << 0 << '\n';
      continue;
    }
    long long prev_k = k;
    if (min(ar, br) >= max(al, bl)) {
      k -= (max(al, bl) - min(al, bl) + max(ar, br) - min(ar, br)) * n;
      ar = max(br, ar);
      br = ar;
      bl = min(al, bl);
      al = bl;
    }
    if (k <= 0) {
      cout << prev_k << '\n';
      continue;
    }
    long long needed = prev_k - k;
    if (al == bl && br == ar) {
      cout << needed + 2 * k << '\n';
      continue;
    }
    for (int i = 1; i <= n; i++) {
      long long pom = min(abs(bl - ar), abs(al - br));
      long long pom2 = max(abs(br - al), abs(ar - bl));
      if (i == 1) {
        needed += pom;
        needed += min(k, pom2);
        k -= min(k, pom2);
      } else {
        if (k < pom) {
          needed += 2 * k;
          k = 0;
        } else {
          needed += pom;
          needed += min(k, pom2);
          k -= min(k, pom2);
        }
      }
      if (k <= 0) break;
    }
    if (k == 0) {
      cout << needed << '\n';
      continue;
    }
    cout << needed + 2 * k << '\n';
  }
  return 0;
}
