#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long a, b, c, r;
    cin >> a >> b >> c >> r;
    if (a == b) {
      cout << '0' << endl;
      continue;
    } else if (a > b) {
      long long f = a;
      a = b;
      b = f;
    }
    if (c <= a) {
      if (c + r > a && c + r >= b)
        cout << '0' << endl;
      else if (c + r <= a)
        cout << b - a << endl;
      else
        cout << abs(b - ((c + r))) << endl;
    } else if (c >= b) {
      if (b > c - r && a > c - r)
        cout << '0' << endl;
      else if (c - r >= b)
        cout << b - a << endl;
      else
        cout << abs(c - r - a) << endl;
    } else {
      long long dis = 0;
      if (c - r > a)
        dis = c - r - a;
      else
        dis = 0;
      if (c + r >= b)
        dis = dis + 0;
      else
        dis = dis + b - (c + r);
      cout << dis << endl;
    }
  }
  return 0;
}
