#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int a, b, c, r;
    cin >> a >> b >> c >> r;
    if (a > b) swap(a, b);
    int x = max(a, c - r), y = min(b, c + r);
    int ans = b - a;
    if (x <= y) ans -= (y - x);
    cout << ans << endl;
  }
}
