#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long a, b, c, r;
    cin >> a >> b >> c >> r;
    if (a > b) {
      long long te = a;
      a = b;
      b = te;
    }
    if (c + r >= b && c - r <= a) {
      cout << 0 << endl;
    } else if (a <= c - r && c + r <= b) {
      cout << ((b - a) - (2 * r)) << endl;
    } else if (a <= c + r && c - r < a) {
      cout << ((b - a) - (c + r - a)) << endl;
    } else if (c - r <= b && c + r > b) {
      cout << ((b - a) - (b - c + r)) << endl;
    } else {
      cout << b - a << endl;
    }
  }
}
