#include <bits/stdc++.h>
using namespace std;
long long const inf = 1e9;
long long const mod = 1e9 + 7;
long double const eps = 1e-9;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long a, b, c, r;
    cin >> a >> b >> c >> r;
    if (a > b) swap(a, b);
    long long L = c - r;
    long long R = c + r;
    if (L < a && R >= a && R <= b) {
      cout << (b - a + 1) - (R - a + 1) << endl;
    } else if (R > b && a <= L && L <= b) {
      cout << (b - a + 1) - (b - L + 1) << endl;
    } else if (a <= L && R <= b) {
      cout << (b - a + 1) - (R - L + 1) << endl;
    } else if (L < a && b < R) {
      cout << 0 << endl;
    } else {
      cout << (b - a) << endl;
    }
  }
  return 0;
}
