#include <bits/stdc++.h>
using namespace std;
int t, u, v, c, r, a, b, s;
int main() {
  cin >> t;
  while (t--) {
    cin >> u >> v >> c >> r;
    a = min(u, v);
    b = max(u, v);
    s = 0;
    if (c < a) {
      if (c + r >= b) {
        cout << 0 << endl;
      } else if (c + r >= a) {
        cout << b - (c + r) << endl;
      } else {
        cout << b - a << endl;
      }
    } else if (c > b) {
      if (c - r <= a) {
        cout << 0 << endl;
      } else if (c - r <= b) {
        cout << c - r - a << endl;
      } else {
        cout << b - a << endl;
      }
    } else {
      u = c - r;
      v = c + r;
      if (u <= a) {
        s = 0;
      } else {
        s = s + u - a;
      }
      if (v < b) {
        s = s + b - v;
      }
      cout << s << endl;
    }
  }
}
