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