#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, k, n, c, r, a, b;
  int tmp;
  list<int> o;
  cin >> t;
  for (t; t > 0; t--) {
    cin >> k;
    cin >> n;
    cin >> c;
    cin >> r;
    a = min(k, n);
    b = max(k, n);
    tmp = b - a;
    if (c <= b && c >= a) {
      tmp -= (min(c - a, r) + min(b - c, r));
    } else if (c <= a) {
      k = max(c + r - a, 0);
      tmp -= min(k, tmp);
    } else {
      k = max(b - (c - r), 0);
      tmp -= min(k, tmp);
    }
    o.push_back(tmp);
  }
  while (!o.empty()) {
    cout << o.front();
    o.pop_front();
    cout << "\n";
  }
}
