#include <bits/stdc++.h>
using namespace std;
long double segmentTree[1200010][3][3];
long double arrayCos[360];
long double arraySin[360];
int lefts[1200010];
int rights[1200010];
int mids[1200010];
long double xs[1200010 / 2];
long double ys[1200010 / 2];
int n;
void passToId(int id) {
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (i == j)
        segmentTree[id][i][j] = 1;
      else
        segmentTree[id][i][j] = 0;
    }
  }
}
void build(int id, int l, int r) {
  passToId(id);
  lefts[id] = l;
  rights[id] = r;
  int mid = (l + r) / 2;
  mids[id] = mid;
  if (l != r) {
    build(id * 2, l, mid);
    build(id * 2 + 1, mid + 1, r);
  }
}
long double mul[3][3];
void mulId() {
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (i == j)
        mul[i][j] = 1;
      else
        mul[i][j] = 0;
    }
  }
}
void multDownFather(int father, int son) {
  long double auxM[3][3];
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      auxM[i][j] = 0;
      for (int k = 0; k < 3; k++) {
        auxM[i][j] += segmentTree[father][i][k] * segmentTree[son][k][j];
      }
    }
  }
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++) segmentTree[son][i][j] = auxM[i][j];
}
void multiplyInterval(int p, int l, int r) {
  if (l == lefts[p] && r == rights[p]) {
    long double auxM[3][3];
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        auxM[i][j] = 0;
        for (int k = 0; k < 3; k++) {
          auxM[i][j] += segmentTree[p][k][j] * mul[i][k];
        }
      }
    }
    for (int i = 0; i < 3; i++)
      for (int j = 0; j < 3; j++) segmentTree[p][i][j] = auxM[i][j];
  } else {
    multDownFather(p, p * 2);
    multDownFather(p, p * 2 + 1);
    passToId(p);
    if (l <= mids[p])
      multiplyInterval(p * 2, max(lefts[p], l), min(mids[p], r));
    if (r >= mids[p] + 1)
      multiplyInterval(p * 2 + 1, max(mids[p] + 1, l), min(rights[p], r));
  }
}
void multiply(int p, int v) {
  long double auxM[3][3];
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      auxM[i][j] = 0;
      for (int k = 0; k < 3; k++) {
        auxM[i][j] += mul[i][k] * segmentTree[p][k][j];
      }
    }
  }
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++) mul[i][j] = auxM[i][j];
  if (lefts[p] != rights[p]) {
    if (v > mids[p])
      multiply(p * 2 + 1, v);
    else
      multiply(p * 2, v);
  }
}
void translation(int id, long double x, long double y) {
  mulId();
  mul[0][2] = x;
  mul[1][2] = y;
  multiplyInterval(1, id, n);
}
void turn(int id, long double x, long double y, int degree) {
  mulId();
  mul[0][0] = arrayCos[degree];
  mul[0][1] = arraySin[degree];
  mul[0][2] = -x * arrayCos[degree] - y * arraySin[degree] + x;
  mul[1][0] = -arraySin[degree];
  mul[1][1] = arrayCos[degree];
  mul[1][2] = x * arraySin[degree] - y * arrayCos[degree] + y;
  multiplyInterval(1, id, n);
}
int main() {
  for (int i = 0; i < 360; i++) {
    long double rad = ((double)(i)) * acos(-1.0) / 180.0;
    arrayCos[i] = cos(rad);
    arraySin[i] = sin(rad);
  }
  std::ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(30);
  int m, x, y, z;
  long double zz, x1, x2, y1, y2, xx, yy, norm;
  cin >> n >> m;
  build(1, 0, n);
  for (int i = 0; i <= n; i++) {
    xs[i] = i + 0.0;
    ys[i] = 0.0;
  }
  for (int i = 0; i < m; i++) {
    cin >> x >> y >> z;
    zz = z;
    mulId();
    multiply(1, y - 1);
    x1 = mul[0][0] * xs[y - 1] + mul[0][1] * ys[y - 1] + mul[0][2];
    y1 = mul[1][0] * xs[y - 1] + mul[1][1] * ys[y - 1] + mul[1][2];
    mulId();
    multiply(1, y);
    x2 = mul[0][0] * xs[y] + mul[0][1] * ys[y] + mul[0][2];
    y2 = mul[1][0] * xs[y] + mul[1][1] * ys[y] + mul[1][2];
    xx = x2 - x1;
    yy = y2 - y1;
    if (x == 1) {
      norm = sqrt(xx * xx + yy * yy);
      xx = xx / norm;
      yy = yy / norm;
      translation(y, xx * zz, yy * zz);
    } else {
      turn(y, x1, y1, z);
    }
    mulId();
    multiply(1, n);
    x1 = mul[0][0] * xs[n] + mul[0][1] * ys[n] + mul[0][2];
    y1 = mul[1][0] * xs[n] + mul[1][1] * ys[n] + mul[1][2];
    cout << x1 << " " << y1 << endl;
  }
  return 0;
}
