#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long a, b, c, r;
    cin >> a >> b >> c >> r;
    if (b < a) swap(a, b);
    cout << (b - a + 1) - (max(min(c + r, b), a) - min(max(a, c - r), b) + 1)
         << "\n";
  }
}
