#include <bits/stdc++.h>
using namespace std;
long long INF = 1 << 28;
const double PI = acos(-1.0);
int dir[4][2] = {1, 0, -1, 0, 0, -1, 0, 1};
int knight[8][2] = {1, 2, 1, -2, 2, 1, 2, -1, -1, 2, -1, -2, -2, 1, -2, -1};
const long double EPS = 1e-7;
struct compare {
  bool operator()(const pair<int, pair<int, int> >& l,
                  const pair<int, pair<int, int> >& r) {
    if (l.first == r.first) {
      return l.second.first > r.second.first;
    }
    return l.first < r.first;
  }
};
const int mx = 300150;
int mod = 1000000007;
int vis[20];
int main() {
  int t, tc = 1;
  scanf("%d", &t);
  while (t--) {
    long long n, k;
    scanf("%lld %lld", &n, &k);
    long long l1, r1, l2, r2;
    scanf("%lld %lld", &l1, &r1);
    scanf("%lld %lld", &l2, &r2);
    long long l3 = max(l1, l2);
    long long r3 = min(r1, r2);
    long long diff = r3 - l3;
    long long pai = max(r1, r2) - min(l1, l2);
    long long ans = 1e18;
    if (diff >= 0) {
      long long already = diff * n;
      k -= already;
      k = max(0LL, k);
      long long ekhanepai = pai - diff;
      long long onemove = ekhanepai * n;
      if (onemove >= k) {
        cout << k << endl;
      } else {
        k -= onemove;
        long long lagbe = onemove;
        lagbe += (k * 2);
        cout << lagbe << endl;
      }
      continue;
    }
    long long banaisi = 0;
    long long lagbe = 0;
    long long bakiase = k;
    diff *= -1;
    for (int i = 1; i <= n; i++) {
      lagbe += diff;
      if (pai >= bakiase) {
        ans = min(ans, lagbe + bakiase);
        break;
      }
      lagbe += pai;
      bakiase -= pai;
      long long tmp = bakiase * 2;
      ans = min(ans, tmp + lagbe);
    }
    cout << ans << endl;
  }
  return 0;
}
