#include <bits/stdc++.h>
const int mod = 1e9 + 7;
const int N = 2e5 + 7;
const int inf = 2e9;
const long long INF = 1e18;
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    long long a, b, c, r;
    cin >> a >> b >> c >> r;
    if (a > b) swap(a, b);
    if (a < c - r) {
      if (b >= c - r)
        cout << c - r - a + max(b - c - r, 0ll) << "\n";
      else
        cout << b - a << "\n";
    } else if (a >= c - r && a <= c + r) {
      cout << max(b - c - r, 0ll) << "\n";
    } else
      cout << b - a << "\n";
  }
}
