#include <iostream>
#include <cmath>
#define PI (acos(-1.0))
using namespace std;
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
int n, R, a, b, c;
double r, sum = 0;
scanf("%d%d", &n, &R);
sum = PI * 2 * R;
while (n--)
{
scanf("%d%d%d", &a, &b, &c);
r = sqrt(a * a + b * b);
if (r >= R + c || r + c < R)
continue;
double a1, a2;
a1 = 2 * acos((double)(r*r + c * c - R * R) / (double)(2.0 * r * c));
a2 = 2 * acos((double)(r*r + R * R - c * c) / (double)(2.0 * r * R));
sum += a1 * c - a2 * R;
}
printf("%.20lf\n", sum);
}
}