#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t;
  cin >> t;
  while (t--) {
    long long int a, b, c, r;
    cin >> a >> b >> c >> r;
    long long int x = c - r;
    long long int y = c + r;
    long long int m1 = a;
    long long int m2 = b;
    a = min(m1, m2);
    b = max(m1, m2);
    if (x <= b && x >= a && y >= b) {
      cout << x - a << endl;
    } else if (x <= a && y <= b && y >= a) {
      cout << b - y << endl;
    } else if (x <= b && y <= b && x >= a && y >= a) {
      cout << b - a - (y - x) << endl;
    } else if (x <= a && y >= b) {
      cout << "0" << endl;
    } else {
      cout << b - a << endl;
    }
  }
  return 0;
}
