#include <bits/stdc++.h>
using namespace std;
const long mod = pow(10, 9) + 7;
int main() {
  long long t1;
  cin >> t1;
  while (t1--) {
    long long a, b, ci, r;
    cin >> a >> b >> ci >> r;
    if (a > b) swap(a, b);
    long long temp = b - a;
    long long c = ci - r, d = ci + r;
    long long ans = 0;
    long long s = 0, e = 0;
    s = max(a, c);
    d = min(d, b);
    ans = d - s;
    if (ans <= 0)
      cout << temp << endl;
    else
      cout << temp - ans << endl;
  }
  return 0;
}
