#include <bits/stdc++.h>
using namespace std;
int main() {
  long long i, j, n, k, m;
  long long t;
  cin >> t;
  long long o = 0;
  while (t--) {
    long long a, b, c, d, r;
    cin >> a >> b >> c >> r;
    if (a > b) swap(a, b);
    d = abs(a - b);
    m = 0;
    if (c >= a && c <= b) {
      m = min(r, c - a);
      m = m + min(r, b - c);
    } else if (c >= a) {
      m = m + max(o, r - (c - b));
    } else {
      m = m + max(o, r - (a - c));
    }
    if (d - m > 0)
      cout << d - m << endl;
    else
      cout << 0 << endl;
  }
}
