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