func_code_string: #include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n, k;       cin >> n >> k;       long long int a, b, c, d;       cin >> a >> b;       cin >> c >> d;       if (a > c || (a == c && b > d)) {         swap(a, c);         swap(b, d);       }       long long int per = max(0LL, c - b);       long long int capacity = max(b, d) - a;       long long int current = max(0LL, min(b, d) - c);       capacity = capacity - current;       k = max(0LL, k - n * current);       if (k == 0) {         cout << 0 << endl;         continue;       }       long long int ans = 0;       ans += per;       long long int num = min(k, capacity);       ans += num;       k -= num;       n--;       if (k == 0) {         cout << ans << endl;         continue;       }       if (per + capacity >= 2 * capacity) {         ans += 2 * k;       } else {         long long int divi = min(k / capacity, n);         ans += (per + capacity) * (divi);         k -= divi * capacity;         if (divi == n || k >= capacity) {           ans += 2 * k;         } else {           if (k + per < 2 * k)             ans += k + per;           else             ans += 2 * k;         }       }       cout << ans << endl;     }     return 0;   }   