#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t, i, j, k, n, l1, r1, l2, r2, x, y, a, b;
  cin >> t;
  for (i = 0; i < t; i++) {
    cin >> n >> k;
    cin >> l1 >> r1;
    cin >> l2 >> r2;
    long long int uni = max(r1, r2) - min(l1, l2);
    long long int intersection = r1 - l1 + r2 - l2 - uni;
    long long int sum = 0;
    long long int result = INT_MAX;
    if (intersection > 0 && n * intersection >= k) {
      cout << 0 << endl;
      continue;
    }
    x = max(0ll, intersection * n);
    for (j = 1; j <= n; j++) {
      sum += max(0ll, -intersection) + min(k - x, uni - max(0ll, intersection));
      x += min(k - x, uni - max(0ll, intersection));
      result = min(result, sum + 2 * (k - x));
      if (x >= k) break;
    }
    cout << result << endl;
  }
  return 0;
}
