#include <bits/stdc++.h>
using namespace std;
long long N, M, K;
long long a, b, c, r, d;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> a >> b >> c >> r;
    d = 0;
    if (a > b) swap(a, b);
    if (a <= c && c <= b) {
      d = max(c - r - a, 0LL) + max(0LL, b - c - r);
    }
    if (b < c) {
      c -= r;
      d = b - a;
      if (c < b) {
        d = max(0LL, c - a);
      }
    }
    if (c < a) {
      d = b - a;
      c += r;
      if (a < c) {
        d = max(0LL, b - c);
      }
    }
    cout << d << "\n";
  }
  return 0;
}
