#include <bits/stdc++.h>
int main() {
  long long int a, b, c, r, min, max, t, m1, m2, ans;
  scanf("%lld", &t);
  while (t--) {
    ans = 0;
    scanf("%lld%lld%lld%lld", &a, &b, &c, &r);
    m1 = (a < b) ? a : b;
    m2 = (a > b) ? a : b;
    min = c - r;
    max = c + r;
    if (min >= m2 || max <= m1)
      ans = m2 - m1;
    else {
      a = min - m1;
      if (a < 0)
        ans += 0;
      else
        ans += a;
      b = m2 - max;
      if (b < 0)
        ans += 0;
      else
        ans += b;
    }
    printf("%lld\n", ans);
  }
}
