#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) {
  if (x == 0 || y == 0) return max(x, y);
  return gcd(max(x, y) % min(x, y), min(x, y));
}
long long i, j;
int t, a, b, c, r, s;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  cin >> t;
  while (t--) {
    s = 0;
    cin >> a >> b >> c >> r;
    if (c - r > min(a, b)) s += min(c - r - min(a, b), abs(a - b));
    if (c + r < max(a, b)) s += min(max(a, b) - (c + r), abs(a - b));
    cout << s << endl;
  }
}
