#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    vector<pair<long long, long long> > a, b;
    long long n, k;
    cin >> n >> k;
    long long al, ar, bl, br;
    cin >> al >> ar;
    cin >> bl >> br;
    if (al > bl) {
      long long tp = al;
      al = bl;
      bl = tp;
      tp = ar;
      ar = br;
      br = tp;
    }
    long long it = min(ar, br) - max(al, bl);
    if (it >= 0) {
      k -= n * it;
      long long p = max(ar, br) - al - (it);
      long long z = 0;
      if (k > n * p) {
        z += n * p;
        k -= n * p;
        z += 2 * k;
      } else {
        z += max(0LL, k);
      }
      cout << z << endl;
    } else {
      long long p = br - al;
      long long mn = 1e18;
      for (long long i = 1; i < n + 1; i = i + 1) {
        long long kk = k;
        long long z = i * (-it);
        if (p * i >= kk) {
          z += kk;
        } else {
          z += p * i;
          kk -= p * i;
          z += 2 * kk;
        }
        mn = min(mn, z);
      }
      cout << mn << endl;
    }
  }
}
