#include <bits/stdc++.h>
using namespace std;
int t, l1, r1, l2, r2, c, r;
int main() {
  cin >> t;
  while (t--) {
    cin >> l1 >> r1 >> c >> r;
    l2 = c - r;
    r2 = c + r;
    if (l1 > r1) swap(l1, r1);
    cout << r1 - l1 - max(0, min(r1, r2) - max(l1, l2)) << endl;
  }
  return 0;
}
