#include <bits/stdc++.h>
using namespace std;
int main() {
  int test;
  cin >> test;
  while (test--) {
    int a_, b_, c, r;
    cin >> a_ >> b_ >> c >> r;
    int b = max(a_, b_);
    int a = min(a_, b_);
    if (c - r < a) {
      if (c + r < a) {
        cout << b - a << endl;
      } else if (c + r < b) {
        cout << b - c - r << endl;
      } else {
        cout << 0 << endl;
      }
    } else if (c - r < b) {
      if (c + r < b) {
        cout << b - a - 2 * r << endl;
      } else {
        cout << c - r - a << endl;
      }
    } else {
      cout << b - a << endl;
    }
  }
  return 0;
}
