#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int a, b, c, r, x, y, z, i, j, k, count = 0, result;
    cin >> a >> b >> c >> r;
    x = c - r;
    y = c + r;
    r = (a >= b) ? a : b;
    z = (a <= b) ? a : b;
    a = z;
    b = r;
    if (x < a && y <= b && y >= a)
      count = y - a;
    else if (x >= a && y <= b)
      count = y - x;
    else if (x < b && x >= a && y > b)
      count = b - x;
    else if (x < a && y > b)
      count = b - a;
    else
      count = 0;
    result = b - a - count;
    cout << result << "\n";
  }
}
