#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
const long double PI = (long double)(3.1415926535897932384626433832795);
void solve() {
  long long a, b, c, r;
  cin >> a >> b >> c >> r;
  if (a > b) {
    swap(a, b);
  }
  long long left = c - r;
  long long right = c + r;
  if (right < a || left > b) {
    cout << (b - a) << endl;
    return;
  }
  long long ans1 = max((long long)0, left - a);
  long long ans2 = max((long long)0, b - right);
  cout << ans1 + ans2 << endl;
}
int main() {
  long long t = 1;
  cin >> t;
  for (long long i = 0; i < t; ++i) {
    solve();
  }
  return 0;
}
