#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long int a, b, c, r;
    cin >> a >> b >> c >> r;
    if (a > b) swap(a, b);
    long long int cover = 0;
    if (c <= a) {
      cover = max(0LL, (c + r) - a);
    } else if (c >= b) {
      cover = max(0LL, b - (c - r));
    } else {
      cover = abs(max(a, (c - r)) - min(b, (c + r)));
    }
    cout << max(0LL, (abs(a - b) - cover)) << endl;
  }
  return 0;
}
