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