#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-6;
const double pi = acos(-1);
const int Max = 50010;
const int maxn = 1e5 + 10;
const int maxh = 4e6 + 10;
const double delta = 0.98;
long long qpow(long long a, long long b, long long c) {
  long long ans = 1;
  a = a % c;
  while (b > 0) {
    if (b & 1) ans = (ans * a) % c;
    b = b >> 1;
    a = (a * a) % c;
  }
  return ans;
}
long long qmul(long long a, long long b, long long c) {
  a = a % c;
  long long ans = 0;
  while (b) {
    if (b & 1) ans = (ans + a) % c;
    b >>= 1;
    a = (a + a) % c;
  }
  return ans;
}
void redirect() {}
int main() {
  redirect();
  int t;
  scanf("%d", &t);
  while (t--) {
    int a, b, c, r;
    scanf("%d%d%d%d", &a, &b, &c, &r);
    if (a > b) swap(a, b);
    int len = b - a;
    int lt, rt;
    lt = c - r;
    rt = c + r;
    long long ans;
    if (r == 0)
      printf("%d\n", len);
    else if (lt >= b || rt <= a)
      printf("%d\n", len);
    else {
      if (lt >= a && rt > b)
        ans = len - (b - lt);
      else if (lt >= a && rt <= b)
        ans = len - (rt - lt);
      else if (lt < a && rt >= b)
        ans = 0;
      else if (lt < a && rt < b)
        ans = len - (rt - a);
      printf("%lld\n", ans);
    }
  }
  return 0;
}
