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