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