#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long a, b, c, r;
  long long t;
  cin >> t;
  ++t;
  while (--t) {
    cin >> a >> b >> c >> r;
    if (a > b) {
      a += b;
      b = a - b;
      a -= b;
    }
    long long sum = 0;
    if ((a <= c) && (b >= c)) {
      sum += max((long long)0, (c - a) - r);
      sum += max((long long)0, (b - c) - r);
    } else {
      if (c <= a) {
        if (a - c >= r)
          sum += b - a;
        else
          sum += max((long long)0, (b - c) - r);
      } else {
        if (c >= b) {
          if (c - b >= r) {
            sum += b - a;
          } else
            sum += max((long long)0, (c - a) - r);
        }
      }
    }
    cout << sum << "\n";
  }
}
