#include <bits/stdc++.h>
using namespace std;
int64_t t, n, k;
int64_t l1, r1;
int64_t l2, r2;
void swap(int64_t& a, int64_t& b) {
  int64_t t = a;
  a = b;
  b = t;
}
int64_t a, b, c;
signed main() {
  cin >> t;
  while (t--) {
    cin >> n >> k;
    cin >> l1 >> r1;
    cin >> l2 >> r2;
    if (l1 > l2) {
      swap(l1, l2);
      swap(r1, r2);
    }
    if (r1 >= r2) {
      a = (r2 - l2);
      b = 0;
      c = (l2 - l1) + (r1 - r2);
    } else if (l2 < r1) {
      a = (r1 - l2);
      b = 0;
      c = (l2 - l1) + (r2 - r1);
    } else {
      a = 0;
      b = l2 - r1;
      c = r2 - l1;
    }
    k -= n * a;
    if (k <= 0) {
      cout << 0 << endl;
      continue;
    }
    if (false) printf("a = %ld, b = %ld, c = %ld\n", a, b, c);
    int64_t cost = b + min(k, c);
    k -= min(k, c);
    if (false) printf("cost = %ld, k = %ld\n", cost, k);
    int64_t remain = n - 1;
    while (remain > 0) {
      int64_t next_cost = b + min(k, c);
      if (next_cost >= 2 * k) break;
      cost += next_cost;
      k -= min(k, c);
      if (false) printf("cost = %ld, k = %ld\n", cost, k);
      remain -= 1;
    }
    cout << cost + (k * 2) << endl;
  }
}
