#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long m, n, k = 1, ans = 0, r;
  cin >> n >> m >> k >> r;
  if (n > m) swap(n, m);
  long long r1 = k - r, r2 = k + r;
  if (r2 < n || r1 > m)
    ans = m - n;
  else
    ans = max(r1 - n, (long long)0) + max(m - r2, (long long)0);
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int q;
  cin >> q;
  while (q--) {
    solve();
  }
  return 0;
}
