#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
int main() {
  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int t;
  cin >> t;
  for (int hh = 1; hh <= t; hh++) {
    int a, b, c, r, aa, bb;
    cin >> aa >> bb >> c >> r;
    int r1, r2;
    r1 = c - r;
    r2 = c + r;
    a = min(aa, bb);
    b = max(aa, bb);
    if (a >= r2) {
      cout << b - a << endl;
      continue;
    }
    if (b <= r1) {
      cout << b - a << endl;
      continue;
    }
    if (a >= r1 && b <= r2) {
      cout << 0 << endl;
      continue;
    }
    if (a < r1 && b > r2) {
      cout << r1 - a + b - r2 << endl;
      continue;
    }
    if (a < r1 && b <= r2) {
      cout << r1 - a << endl;
      continue;
    }
    if (a >= r1 && b > r2) {
      cout << b - r2 << endl;
      continue;
    }
  }
  return 0;
}
