#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc;
  cin >> tc;
  while (tc--) {
    int a, b, c, r;
    cin >> a >> b >> c >> r;
    if (b < a) swap(a, b);
    int l1 = c - r;
    int l2 = c + r;
    int ans = 0;
    if (l1 >= a) {
      ans += min(l1, b) - a;
    }
    if (l2 <= b) {
      ans += b - max(a, l2);
    }
    cout << ans << '\n';
  }
  return 0;
}
