#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 13;
const int MOD = 1e9 + 7;
const int INF = INT_MAX;
const long long INFL = LLONG_MAX;
const unsigned long long INFUL = ULLONG_MAX;
const double PI = acos(-1);
void solve() {
  long long a, b, c, r;
  cin >> a >> b >> c >> r;
  long long sum = 0;
  long long l1 = min(a, b), r1 = max(a, b);
  long long l2 = c - r, r2 = c + r;
  if (l1 <= l2 && r2 <= r1) {
    cout << abs(a - b) - (r2 - l2) << "\n";
  } else if (l2 <= l1 && r1 <= r2) {
    cout << "0\n";
  } else if (r1 <= l2) {
    cout << abs(a - b) << "\n";
  } else if (l1 >= r2) {
    cout << abs(a - b) << "\n";
  } else if (l2 < l1) {
    cout << abs(b - a) - (r2 - l1) << "\n";
  } else if (r1 < r2) {
    cout << abs(a - b) - (r1 - l2) << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int q;
  cin >> q;
  while (q--) {
    solve();
  }
  return 0;
}
