#include <bits/stdc++.h>
using namespace std;
int t;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> t;
  while (t--) {
    int a, b, c, r, d;
    cin >> a >> b >> c >> r;
    if (a > b) {
      swap(a, b);
    }
    d = c + r;
    c = c - r;
    if (c > b || d < a) {
      cout << max(0, abs(b - a)) << '\n';
    } else {
      if (c >= a && d <= b) {
        cout << max(0, abs(b - a) - abs(d - c)) << '\n';
      } else {
        if (c < a && d >= a) {
          cout << max(0, abs(b - a) - abs(d - a)) << '\n';
        } else {
          cout << max(0, abs(b - a) - abs(b - c)) << '\n';
        }
      }
    }
  }
  return 0;
}
