#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int tc;
  cin >> tc;
  while (tc--) {
    long long a, b, c, r;
    cin >> a >> b >> c >> r;
    if (a > b) swap(a, b);
    long long left = c - r, right = c + r;
    long long dist = 0;
    if (b < left) {
      cout << b - a << '\n';
    } else if (a > right) {
      cout << b - a << '\n';
    } else {
      dist += max(0ll, left - a);
      dist += max(0ll, b - right);
      cout << dist << '\n';
    }
  }
  return 0;
}
