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