#include <bits/stdc++.h>
using namespace std;
int t, a, b, c, r, ans;
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d%d%d", &a, &b, &c, &r);
    if (a > b) swap(a, b);
    int L = c - r, R = c + r;
    if (a <= L && R <= b) {
      ans = L - a + b - R;
    } else if (L <= a && b <= R) {
      ans = 0;
    } else if (b <= L || a >= R) {
      ans = b - a;
    } else {
      if (a <= L && L <= b)
        ans = L - a;
      else
        ans = b - R;
    }
    printf("%d\n", ans);
  }
  return 0;
}
