#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long a, b, c, r;
    cin >> a >> b >> c >> r;
    if (a > b) swap(a, b);
    long long time = 0;
    long long left = c - r, right = c + r;
    if (right < a || left > b) {
      cout << b - a << '\n';
      continue;
    }
    long long ans =
        (c - r - a >= 0 ? c - r - a : 0) + (b - c - r >= 0 ? b - c - r : 0);
    cout << ans << '\n';
    continue;
  }
}
