#include <bits/stdc++.h>
using namespace std;
long long n, k, l[2], r[2];
void reset() {}
void input() {
  cin >> n >> k;
  for (long long(j) = (0); (j) < (2); (j)++) {
    cin >> l[j] >> r[j];
  }
}
void solve() {
  if (l[0] > l[1]) {
    swap(l[0], l[1]);
    swap(r[0], r[1]);
  }
  long long best = LLONG_MAX;
  for (long long(i) = (1); (i) <= (n); (i)++) {
    long long cost = 0, range = 0;
    if (l[1] >= r[0]) {
      if (r[0] <= l[1]) {
        range = l[1] - r[0];
        cost = l[1] - r[0];
        cost *= i;
      }
      if ((r[1] - l[0]) * i >= k) {
        cost += k;
      } else {
        cost += (r[1] - l[0]) * i;
        long long need = k - ((r[1] - l[0]) * i);
        cost += need * 2;
      }
    } else if (r[1] <= r[0] && l[1] >= l[0]) {
      long long need = k - n * (r[1] - l[1]);
      if (need > 0) {
        if (i * (r[0] - r[1]) + i * (l[1] - l[0]) >= need) {
          cost += need;
        } else {
          need -= i * (r[0] - r[1]) + i * (l[1] - l[0]);
          cost += i * (r[0] - r[1]) + i * (l[1] - l[0]);
          cost += need * 2;
        }
      }
    } else {
      long long need = k - n * (r[0] - l[1]);
      if (need >= 0) {
        if ((r[1] - r[0]) * i + i * (l[1] - l[0]) >= need) {
          cost += need;
        } else {
          long long reduce = abs(r[1] - r[0]) * i + i * abs(l[1] - l[0]);
          need -= reduce;
          cost += abs(r[1] - r[0]) * i + i * abs(l[1] - l[0]);
          cost += need * 2;
        }
      }
    }
    best = min(best, cost);
  }
  cout << best << endl;
}
void LetsRock() { solve(); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int T;
  cin >> T;
  while (T--) {
    reset();
    input();
    LetsRock();
  }
  return 0;
}
