#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int a, b, c, r;
    cin >> a >> b >> c >> r;
    int l_c = c - r;
    int r_c = c + r;
    if (a >= l_c && a <= r_c && b >= l_c && b <= r_c) {
      cout << 0 << "\n";
      continue;
    }
    if (a > b) {
      int temp = a;
      a = b;
      b = temp;
    }
    int new_a = 0;
    int new_b = abs(b - a);
    int new_c = c >= a ? (abs(c - a)) : (-abs(c - a));
    a = new_a;
    b = new_b;
    c = new_c;
    if (c <= a and c < b) {
      long dist = b - (c + r);
      if (dist < 0)
        cout << 0 << "\n";
      else if (dist > (b - a))
        cout << b - a << "\n";
      else
        cout << dist << "\n";
    } else if (c > a and c < b) {
      long dista = (c - r) - a;
      if (dista < 0) dista = 0;
      long distb = b - (c + r);
      if (distb < 0) distb = 0;
      cout << dista + distb << "\n";
    } else if (c > a and c >= b) {
      long dist = (c - r) - a;
      if (dist < 0)
        cout << 0 << "\n";
      else if (dist > (b - a))
        cout << b - a << "\n";
      else
        cout << dist << "\n";
    }
  }
  return 0;
}
