#include <bits/stdc++.h>
int main() {
  int t, a, b, c, r;
  int time;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d%d%d", &a, &b, &c, &r);
    a > b ? (a ^= b), (b ^= a), (a ^= b) : (b = b);
    int left = c - r, right = c + r;
    if (a <= c && b >= c) {
      if (left <= a) {
        if (right <= b) {
          printf("%d\n", b - right);
        } else {
          printf("0\n");
        }
      } else {
        if (b > right) {
          printf("%d\n", left - a + b - right);
        } else {
          printf("%d\n", left - a);
        }
      }
    } else if (c < a) {
      if (right < a) {
        printf("%d\n", b - a);
      } else if (right >= b)
        printf("0\n");
      else {
        printf("%d\n", b - right);
      }
    } else {
      if (left <= a)
        printf("0\n");
      else if (left > b)
        printf("%d\n", b - a);
      else
        printf("%d\n", left - a);
    }
  }
  return 0;
}
