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