#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int test;
  cin >> test;
  while (test--) {
    long a, b, c, r;
    cin >> a >> b >> c >> r;
    if (a > b) {
      a ^= b;
      b ^= a;
      a ^= b;
    }
    long left = c - r, right = c + r;
    if (left >= b || right <= a) {
      cout << abs(a - b) << '\n';
    } else if (left <= a && right >= b) {
      cout << 0 << '\n';
    } else if (left > a && right < b) {
      cout << (abs(a - left) + abs(b - right)) << '\n';
    } else if (left < b && right >= b) {
      cout << abs(a - left) << '\n';
    } else if (right > a && left <= a) {
      cout << abs(right - b) << '\n';
    }
  }
  return 0;
}
