#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
int main() {
  int t;
  cin >> t;
  while (t--) {
    int a, b, c, r;
    cin >> a >> b >> c >> r;
    int ac = a;
    int bc = b;
    b = max(ac, bc);
    a = min(ac, bc);
    int left = c - r;
    int right = r + c;
    if (right <= a || left >= b) {
      cout << b - a << endl;
    } else {
      left = max(left, a);
      right = min(right, b);
      cout << abs(left - a) + (abs(b - right)) << endl;
    }
  }
}
