#include <bits/stdc++.h>
using namespace std;
template <class T>
void show(const vector<T> &a) {
  for (T x : a) cout << x << " ";
  cout << '\n';
}
const long long N = 3e5 + 100, oo = 2e18;
const long long mod = 1e9 + 9;
const long double eps = 1e-9, PI = 2 * acos(0.0);
long long n, m, k;
long long cnt = 0;
vector<long long> g[N];
vector<long long> visit(N, 0);
long long sect(long long a, long long b, long long c, long long d) {
  long long r = min(b, d);
  long long l = max(a, c);
  if (r >= l) {
    return r - l;
  }
  return 0;
}
signed main() {
  ios::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long a, b, c, r;
    cin >> a >> b >> c >> r;
    a += 1e9;
    b += 1e9;
    c += 1e9;
    if (a > b) swap(a, b);
    long long val = sect(a, b, c - r, c + r);
    cout << b - a - val << '\n';
  }
}
