#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  for (long long i = 0; i < t; i++) {
    long long n, k, x = 0;
    cin >> n >> k;
    long long a1, b1, a2, b2;
    cin >> a1 >> b1 >> a2 >> b2;
    long long r1[2], r2[2];
    r1[0] = max(a1, a2);
    r1[1] = min(b1, b2);
    long long d1 = r1[1] - r1[0];
    if (k <= n * (r1[1] - r1[0])) {
      cout << "0" << endl;
      continue;
    } else {
      k -= (d1 > 0 ? n * d1 : 0);
      r2[1] = max(b1, b2);
      r2[0] = min(a1, a2);
      long long d = r2[1] - r2[0];
      long long z = d - d1;
      if (d1 <= 0) {
        if (k < d) {
          x += k - d1;
          k -= k;
        } else {
          k -= d;
          x += z;
        }
        for (long long j = 1; j < n; j++) {
          if (k == 0) break;
          if (k < d) {
            long long h = k - d1;
            x += min(h, k * 2);
            k = 0;
            break;
          } else {
            x += min(k * 2, z);
            k -= d;
          }
        }
        x += 2 * k;
      } else if (d1 > 0) {
        if (k < z) {
          x += k;
          k -= k;
        } else {
          x += z;
          k -= z;
        }
        for (long long j = 1; j < n; j++) {
          if (k == 0) break;
          if (k < z) {
            x += k;
            k = 0;
          } else {
            x += min(z, 2 * k);
            k -= z;
          }
        }
        x += 2 * k;
      }
    }
    cout << x << endl;
  }
  return 0;
}
