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