#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t, i, j, a, b, c, r, x, y, ans, res1, res2, p, q;
  cin >> t;
  while (t--) {
    cin >> p >> q >> c >> r;
    a = min(p, q);
    b = max(p, q);
    x = c + r;
    y = c - r;
    ans = abs(b - a);
    res1 = min(x, b);
    res2 = max(y, a);
    if (res1 >= a && res1 <= b && res2 >= a && res2 <= b)
      cout << ans - (res1 - res2) << '\n';
    else
      cout << ans << '\n';
  }
  return 0;
}
