#include <bits/stdc++.h>
#pragma GCC optimize(2)
inline int read() {
  int num = 0, w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) {
    num = (num << 3) + (num << 1) + (ch ^ 48);
    ch = getchar();
  }
  return w ? -num : num;
}
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
using namespace std;
int a, b, c, r;
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int t, t1, t2;
  cin >> t;
  while (t--) {
    cin >> t1 >> t2 >> c >> r;
    a = (t1 > t2 ? t2 : t1);
    b = (t1 < t2 ? t2 : t1);
    int ans = b - a;
    if (c < a && c + r > a)
      ans -= (c + r - a);
    else if (c > b && c - r < b)
      ans -= (b - (c - r));
    else if (c >= a && c <= b) {
      int temp = 2 * r;
      if (c + r > b) temp -= c + r - b;
      if (c - r < a) temp -= a - (c - r);
      ans -= temp;
    }
    cout << (ans < 0 ? 0 : ans) << endl;
  }
  return 0;
}
