#include <bits/stdc++.h>
const int INF = 1000000009;
const int MAXN = 200008;
const int MOD = 1000000007;
const double PI = 3.14159265359;
const double EPS = 1e-6;
using namespace std;
int n, p, k, m, test, ans;
int sft = 100000000;
int main() {
  cin >> test;
  while (test--) {
    int a, b, c, r;
    cin >> a >> b >> c >> r;
    a += sft;
    b += sft;
    c += sft;
    if (a > b) swap(a, b);
    int intr = min(b, c + r) - max(a, c - r);
    cout << (b - a) - max(0, intr) << '\n';
  }
  return 0;
};
