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