#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a > b) swap(a, b);
    long long l = c - d;
    long long r = c + d;
    if (b <= l) {
      cout << b - a << endl;
      continue;
    } else if (b <= r) {
      if (a <= l) {
        cout << l - a << endl;
        continue;
      }
      cout << 0 << endl;
    } else {
      if (a <= l) {
        cout << b - r + l - a << endl;
        continue;
      } else if (a > l && a < r) {
        cout << b - r << endl;
      } else {
        cout << b - a << endl;
      }
    }
  }
}
