#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, a, b, c, r, l, d;
  cin >> t;
  while (t--) {
    cin >> a >> b >> c >> r;
    if (a > b) swap(a, b);
    l = c - r;
    r = c + r;
    if (r <= a || l >= b) {
      cout << b - a << endl;
      continue;
    }
    if (l >= a && r <= b) {
      cout << l - a + b - r << endl;
      continue;
    }
    if (l < a && r > b) {
      cout << "0" << endl;
      continue;
    }
    if (l >= a && r > b) {
      cout << l - a << endl;
      continue;
    }
    if (l < a && r >= a && r <= b) {
      cout << b - r << endl;
      continue;
    }
  }
  return 0;
}
