#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
long long T, L1, L2, R1, R2, n, k;
int main() {
  cin >> T;
  while (T--) {
    cin >> n >> k;
    cin >> L1 >> R1 >> L2 >> R2;
    long long ans = 0;
    if (R1 < L2 or R2 < L1) {
      if (R1 > L2) {
        swap(L1, L2);
        swap(R1, R2);
      }
      long long cnt = L2 - R1;
      L2 = R1;
      long long a = abs(R2 - R1) + abs(L2 - L1);
      if (a * n >= k) {
        if (k / a == 0) {
          ans += cnt + k;
        } else {
          ans += k / a * (cnt + a);
          k %= a;
          if (k != 0) ans += min(cnt + k, k * 2);
        }
      } else {
        k -= a * n;
        ans += n * (a + cnt);
        ans += k * 2;
      }
    } else {
      long long a = abs(R2 - R1) + abs(L2 - L1);
      long long b = max(R1, R2) - min(L1, L2) - (abs(R2 - R1) + abs(L2 - L1));
      if (n * b <= k) {
        k -= n * b;
        if (a * n >= k) {
          ans += k;
        } else {
          k -= a * n;
          ans += a * n;
          ans += k * 2;
        }
      }
    }
    cout << ans << endl;
  }
}
