#include <bits/stdc++.h>
using namespace std;
long long exp(long long x, long long y, long long p) {
  long long res = 1;
  while (y) {
    if (y % 2) res = (res * x % p) % p;
    x = (x * x) % p;
    y /= 2;
  }
  return res;
}
long long exp(long long x, long long y) {
  long long res = 1;
  while (y) {
    if (y % 2) res = (res * x);
    x = (x * x);
    y /= 2;
  }
  return res;
}
int sv[1000000] = {0};
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long a, b, c, r;
    cin >> a >> b >> c >> r;
    if (a > b) swap(a, b);
    if ((c + r <= a) || (c - r >= b)) {
      cout << b - a << endl;
      continue;
    }
    cout << max(a, c - r) - a - min(c + r, b) + b << endl;
  }
  return 0;
}
