#include <bits/stdc++.h>
long int max(long int x, long int y) {
  x = (x >= y) ? x : y;
  return x;
}
long int min(long int x, long int y) {
  x = (x <= y) ? x : y;
  return x;
}
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int a, b, c, r, x, y, initial, final, result;
    cin >> a >> b >> c >> r;
    x = c - r;
    y = c + r;
    initial = max(x, min(a, b));
    final = min(y, max(a, b));
    result = abs(b - a) - max(0, final - initial);
    cout << result << "\n";
  }
  return 0;
}
