#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;
    int start, end;
    start = max((c - r), min(a, b));
    end = min((c + r), max(a, b));
    cout << abs(b - a) - max(0, (end - start)) << endl;
  }
}
