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