#include <bits/stdc++.h>
using namespace std;
void eat() {
  long long n, k, i, j, l1, r1, l2, r2, x, y, z, a, b, c;
  cin >> n >> k >> l1 >> r1 >> l2 >> r2;
  if (r1 >= l2 && r2 >= l1) {
    a = min(r1, r2) - max(l1, l2);
    x = abs(l1 - l2) + abs(r1 - r2);
    k -= a * n;
    if (k < n * x) {
      z = max(k, (long long)0);
    } else {
      z = n * x + (k - n * x) * 2;
    }
  } else {
    if (l2 < l1) {
      a = l1, b = r1, l1 = l2, r1 = r2, l2 = a, r2 = b;
    }
    a = r1 - l1 + r2 - l2, b = l2 - r1;
    if (k < (a + b) * n) {
      x = k / (a + b);
      z = (a + b * 2) * x;
      y = k % (a + b) + b;
      if (x) {
        y = min(y, (k % (a + b)) * 2);
      }
      z += y;
    } else {
      z = (a + b * 2) * n + (k - (a + b) * n) * 2;
    }
  }
  cout << z << '\n';
  return;
}
int main() {
  long long t, ti;
  cin >> t;
  for (ti = 0; ti < t; ti++) {
    eat();
  }
  return 0;
}
