1 #include <bits/stdc++.h>
2 using namespace std;
3 const double eps = 1e-5;
4 double a, b, l, r;
5
6 double F(double x) {
7 //Simpson公式用到的函数
8 return sqrt((a * a * b * b - b * b * x * x) / a / a);
9 }
10 double simpson(double a, double b) { //三点Simpson法,这里要求F是一个全局函数
11 double c = a + (b - a) / 2;
12 return (F(a) + 4 * F(c) + F(b))*(b - a) / 6;
13 }
14 double asr(double a, double b, double eps, double A) { //自适应Simpson公式(递归过程)。已知整个区间[a,b]上的三点Simpson值A
15 double c = a + (b - a) / 2;
16 double L = simpson(a, c), R = simpson(c, b);
17 if (fabs(L + R - A) <= 15 * eps)return L + R + (L + R - A) / 15.0;
18 return asr(a, c, eps / 2, L) + asr(c, b, eps / 2, R);
19 }
20 double asr(double a, double b, double eps) {
21 return asr(a, b, eps, simpson(a, b));
22 }
23
24
25 int main(){
26 int n;
27 //freopen("in.txt", "r", stdin);
28 scanf("%d", &n);
29 for(int i = 0; i < n; i++){
30 scanf("%lf %lf %lf %lf", &a, &b, &l, &r);
31 printf("%.3lf\n", 2 *asr(l, r, eps));
32 }
33 }