#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, a, b, c, r;
  cin >> t;
  while (t--) {
    int ans;
    cin >> a >> b >> c >> r;
    if (a == b) {
      cout << "0" << endl;
      continue;
    }
    if (a > b) {
      int dis = a - b;
      int left = c - r;
      int right = c + r;
      if (left >= a || right <= b) {
        ans = dis;
      }
      if (left <= b && right >= a) {
        ans = 0;
      }
      if (right > b && right < a && left < b) {
        ans = dis - (right - b);
      }
      if (left >= b && right <= a) {
        ans = dis - 2 * r;
      }
      if (left < a && left > b && right > a) {
        ans = dis - (a - left);
      }
    }
    if (a < b) {
      int dis = b - a;
      int left = c - r;
      int right = c + r;
      if (left >= b || right <= a) {
        ans = dis;
      }
      if (left <= a && right >= b) {
        ans = 0;
      }
      if (right > a && right < b && left < a) {
        ans = dis - (right - a);
      }
      if (left >= a && right <= b) {
        ans = dis - 2 * r;
      }
      if (left < b && left > a && right > b) {
        ans = dis - (b - left);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
