#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;
    if (a > b) swap(b, a);
    if (c + r <= b && c - r >= a)
      cout << abs(b - a - 2 * r) << endl;
    else if (c + r > b && c - r >= a && c - r < b)
      cout << abs(a - (c - r)) << endl;
    else if (c - r < a && c + r <= b && c + r > a)
      cout << abs(b - (c + r)) << endl;
    else if (c - r < a && c + r > b)
      cout << '0' << endl;
    else
      cout << abs(b - a) << endl;
  }
  return 0;
}
