#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, a, b, c, d, n, t, x, y;
  while (cin >> n) {
    while (n--) {
      cin >> a >> b >> c >> d;
      if (a > b) {
        t = a;
        a = b;
        b = t;
      }
      if (d == 0 || c - d >= b || c + d <= a)
        cout << (b - a) << endl;
      else {
        x = c - d;
        y = c + d;
        if (x >= a && y <= b)
          cout << (b - a - y + x) << endl;
        else if (x <= a && y >= b)
          cout << 0 << endl;
        else if (x < a && y > a && y <= b)
          cout << (b - y) << endl;
        else if (x > a && x < b && y > b)
          cout << (x - a) << endl;
      }
    }
  }
  return 0;
}
