#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int a, b, c, r;
    cin >> a >> b >> c >> r;
    if (a > b) swap(a, b);
    int rlower = c - r;
    int rupper = c + r;
    if (rupper < a || b < rlower) {
      cout << (b - a) << endl;
      continue;
    }
    int ans = 0;
    if (rlower > a) ans += (rlower - a);
    if (rupper < b) ans += (b - rupper);
    cout << ans << endl;
  }
  return 0;
}
