#include <bits/stdc++.h>
using namespace std;
using namespace std;
int main() {
  int test;
  cin >> test;
  while (test--) {
    int a, b, c, r;
    cin >> a >> b >> c >> r;
    int left = c - r;
    int right = c + r;
    int start = max(left, min(a, b));
    int endd = min(right, max(a, b));
    cout << abs(a - b) - max(0, (endd - start)) << endl;
  }
}
