#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int _;
  cin >> _;
  while (_--) {
    long long int i, n, k;
    cin >> n >> k;
    long long int l1, r1, l2, r2;
    cin >> l1 >> r1;
    cin >> l2 >> r2;
    if (l1 > l2) {
      swap(l1, l2);
      swap(r1, r2);
    }
    long long int cnt = 0;
    if (l2 > r1) {
      long long int len = r2 - l1;
      long long int waste = l2 - r1;
      cnt += waste;
      if (k <= len) {
        cnt += k;
        cout << cnt << "\n";
        continue;
      } else {
        cnt += len;
        k -= len;
      }
      for (i = 1; i < n; i++) {
        if (waste >= k) {
          cnt += (2 * k);
          k = 0;
          break;
        } else {
          cnt += waste;
          if (k <= len) {
            cnt += k;
            k = 0;
            break;
          } else {
            cnt += len;
            k -= len;
          }
        }
      }
      if (k == 0) {
        cout << cnt << "\n";
      } else {
        cnt += (2 * k);
        cout << cnt << "\n";
      }
    } else {
      long long int len = max(r1, r2) - min(l1, l2);
      long long int inter = min(r1, r2) - l2;
      k -= (n * inter);
      if (k <= 0) {
        cout << 0 << "\n";
        continue;
      } else {
        for (i = 0; i < n; i++) {
          if (k <= (len - inter)) {
            cnt += k;
            k = 0;
            break;
          } else {
            k -= (len - inter);
            cnt += (len - inter);
          }
        }
        if (k == 0) {
          cout << cnt << "\n";
          continue;
        } else {
          cnt += (2 * k);
          cout << cnt << "\n";
          continue;
        }
      }
    }
  }
}
