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