#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    long long a, b, c, r;
    cin >> a >> b >> c >> r;
    if (a > b) swap(a, b);
    long long p1 = c - r, p2 = c + r;
    p1 = max(p1, a), p2 = min(p2, b);
    cout << b - a + 1 - max((long long)1, (p2 - p1 + 1)) << endl;
  }
}
