#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int a, b, c, r, ans;
    cin >> a >> b >> c >> r;
    if (b < a) {
      long long int temp = a;
      a = b;
      b = temp;
    }
    if (c <= a) {
      long long int x = c + r;
      if (c + r <= a)
        ans = b - a;
      else if (x >= b)
        ans = 0;
      else
        ans = b - x;
    } else if (c >= b) {
      long long int x = c - r;
      if (x >= b)
        ans = b - a;
      else if (x <= a)
        ans = 0;
      else
        ans = x - a;
    } else {
      long long int x1 = c - r, x2 = c + r;
      if (x1 <= a) x1 = a;
      if (x2 >= b) x2 = b;
      ans = x1 - a + b - x2;
    }
    cout << ans << endl;
  }
  return 0;
}
