#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &res) {
  char c;
  T flag = 1;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') flag = -1;
  res = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') res = res * 10 + c - '0';
  res *= flag;
}
template <class T>
inline void prin(T x) {
  if (x > 9) prin(x / 10);
  putchar(x % 10 + '0');
}
const int MOD = 2333;
const int MAX = 2e5 + 10;
const int MAXN = 1e7 + 10;
const int inf = 2e5 + 100;
long double PI = 3.14159265358979323846;
int t;
long long aa, bb, d, R;
int main() {
  cin >> t;
  while (t--) {
    cin >> aa >> bb >> d >> R;
    if (aa > bb) {
      swap(aa, bb);
    }
    long long m = d - R;
    long long n = d + R;
    if (m > bb || n < aa) {
      cout << bb - aa << endl;
      continue;
    }
    if (m <= aa && n >= bb) {
      cout << 0 << endl;
      continue;
    }
    if (m <= aa && bb > n) {
      cout << bb - n << endl;
      continue;
    }
    if (m > aa && bb <= n) {
      cout << m - aa << endl;
      continue;
    }
    if (m > aa && bb > n) {
      cout << m - aa + bb - n << endl;
      continue;
    }
  }
  return 0;
}
