#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<double,double> P;

class Point {
public:
	double x, y;
	Point() {}
	Point(double xx, double yy) {
		x = xx;
		y = yy;
	}
	Point operator +(Point p) {
		return Point(x + p.x, y + p.y);
	}
	Point operator -(Point p) {
		return Point(x - p.x, y - p.y);
	}
	Point operator *(double a) {
		return Point(a * x, a * y);
	}
	Point operator /(double a) {
		return Point(x / a, y / a);
	}

	double abs() {
		return sqrt(norm());
	}
	double norm() {
		return x * x + y * y;
	}
};

int n,d;
double l[101],r[101],t[101];
Point p;
double dir;

void solve(){
	p=Point(0,0);
	dir=0.0;
	for(int i=0;i<n;i++){
		if(l[i]==r[i]){
			p.x+=(double)l[i]*t[i]*cos(dir+M_PI/2);
			p.y+=(double)l[i]*t[i]*sin(dir+M_PI/2);
		}else if(l[i]==0){
			double lx=p.x-d*cos(dir);
			double ly=p.y-d*sin(dir);
			dir+=r[i]*t[i]/(2.0*d);
			p.x=lx+d*cos(dir);
			p.y=ly+d*sin(dir);
		}else if(r[i]==0){
			double rx=p.x+d*cos(dir);
			double ry=p.y+d*sin(dir);
			dir-=(double)l[i]*t[i]/(2.0*d);
			p.x=rx-d*cos(dir);
			p.y=ry-d*sin(dir);
		}else if(l[i]<r[i]){
			if(l[i]>0){
				double cd=(double)(r[i]-l[i])*t[i]/(2.0*d);
				double rv=(double)(2.0*d*l[i])/(r[i]-l[i]);
				double lx=p.x-(d+rv)*cos(dir);
				double ly=p.y-(d+rv)*sin(dir);
				dir+=cd;
				p.x=lx+(d+rv)*cos(dir);
				p.y=ly+(d+rv)*sin(dir);
			}else if(r[i]>0){
				double mid=(double)fabs(l[i])/(fabs(l[i])+fabs(r[i]));
				double cd=(double)-l[i]*t[i]/(mid*d*2.0);
				double mx=p.x+(mid-0.5)*2.0*d*cos(dir);
				double my=p.y+(mid-0.5)*2.0*d*sin(dir);
				dir+=cd;
				p.x=mx-(mid-0.5)*2.0*d*cos(dir);
				p.y=my-(mid-0.5)*2.0*d*sin(dir);
			}else{
				double cd=(double)(l[i]-r[i])*t[i]/(2.0*d);
				double rv=(double)(2.0*d*r[i])/(l[i]-r[i]);
				double lx=p.x+(d+rv)*cos(dir);
				double ly=p.y+(d+rv)*sin(dir);
				dir-=cd;
				p.x=lx-(d+rv)*cos(dir);
				p.y=ly-(d+rv)*sin(dir);
			}
		}else{
			if(r[i]>0){
				double cd=(double)(l[i]-r[i])*t[i]/(2.0*d);
				double rv=(double)(2.0*d*r[i])/(l[i]-r[i]);
				double lx=p.x+(d+rv)*cos(dir);
				double ly=p.y+(d+rv)*sin(dir);
				dir-=cd;
				p.x=lx-(d+rv)*cos(dir);
				p.y=ly-(d+rv)*sin(dir);
			}else if(l[i]>0){
				double mid=(double)fabs(l[i])/(fabs(l[i])+fabs(r[i]));
				double cd=(double)-l[i]*t[i]/(mid*d*2.0);
				double mx=p.x+(mid-0.5)*2.0*d*cos(dir);
				double my=p.y+(mid-0.5)*2.0*d*sin(dir);
				dir+=cd;
				p.x=mx-(mid-0.5)*2.0*d*cos(dir);
				p.y=my-(mid-0.5)*2.0*d*sin(dir);
			}else{
				double cd=(double)(r[i]-l[i])*t[i]/(2.0*d);
				double rv=(double)(2.0*d*l[i])/(r[i]-l[i]);
				double lx=p.x-(d+rv)*cos(dir);
				double ly=p.y-(d+rv)*sin(dir);
				dir+=cd;
				p.x=lx+(d+rv)*cos(dir);
				p.y=ly+(d+rv)*sin(dir);
			}
		}
	}
	printf("%.9f\n%.9f\n",p.x,p.y);
}

int main(void){
	while(1){
		scanf("%d%d",&n,&d);
		if(n==0 && d==0)break;
		for(int i=0;i<n;i++){
			scanf("%lf%lf%lf",&l[i],&r[i],&t[i]);
			l[i]/=180.0;
			r[i]/=180.0;
			l[i]*=M_PI;
			r[i]*=M_PI;
		}
		solve();
	}
	
	return 0;
}
