#include <cassert>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <vector>

using namespace std;

unsigned long long lcgSeed = 301703;
int nextRnd( int l, int r )
{
  lcgSeed = lcgSeed * 23917 + 997;
  int res = (lcgSeed >> 16) % (r - l + 1) + l;
  return res;
}

typedef pair <int, int> point;

int testN, testD, testT;

vector <point> randomPath()
{
  point current = point(0, 0);
  vector <point> result;
  for (int i = 0; i < testN; i++)
  {
    int dx, dy;
    do
    {
      dx = nextRnd(-testT, testT);
      dy = nextRnd(-testT, testT);
    }
    while (abs(dx) + abs(dy) > testT);
    current.first += dx;
    current.second += dy;
    result.push_back(current);
  }
  return result;
}

void randomTest( vector <point> points )
{
  assert(printf("Случайный тест (t=%d,d=%d,n=%d)\n", testT, testD, testN) >= 0);
  assert(printf("%d %d %d\n", testT, testD, testN) >= 0);
  for (int i = 0; i < testN; i++)
  {
    int dx, dy;
    do
    {
      dx = nextRnd(-testD, testD);
      dy = nextRnd(-testD, testD);
    }
    while (abs(dx) + abs(dy) > testD);
    assert(printf("%d %d\n", points[i].first + dx, points[i].second + dy) >= 0);
  }
  assert(puts("") >= 0);
}

void lineTest( int dx, int dy )
{
  assert(printf("Миша бежит в одну сторону (t=%d,d=%d,n=%d)\n", testT, testD, testN) >= 0);
  assert(printf("%d %d %d\n", testT, testD, testN) >= 0);
  int pos = 0;
  for (int i = 0; i < testN; i++)
  {
    int x = (pos + testT + testD) * dx;
    int y = (pos + testT + testD) * dy;
    pos += testT;
    assert(printf("%d %d\n", x, y) >= 0);
  }
  assert(puts("") >= 0);
}

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

void jumpTest( vector <point> points )
{
  assert(printf("Случайный тест с прыжком в конце (t=%d,d=%d,n=%d)\n", testT, testD, testN + 1) >= 0);
  assert(printf("%d %d %d\n", testT, testD, testN + 1) >= 0);
  int lastX = 0, lastY = 0;
  for (int i = 0; i < testN; i++)
  {
    int dx, dy;
    do
    {
      dx = nextRnd(-testD, testD);
      dy = nextRnd(-testD, testD);
    }
    while (abs(dx) + abs(dy) > testD);
    assert(printf("%d %d\n", points[i].first + dx, points[i].second + dy) >= 0);
    lastX = points[i].first, lastY = points[i].second;
  }
  int dd = nextRnd(0, 3);
  assert(printf("%d %d\n", lastX + dx[dd] * (testT + testD), lastY + dy[dd] * (testT + testD)) >= 0);
  assert(puts("") >= 0);
}

int main()
{
  for (int i = 0; i < 10; i++)
  {
    testN = nextRnd(1, 20);
    testT = nextRnd(1, 10);
    testD = nextRnd(1, 10);
    randomTest(randomPath());
  }
  for (int i = 0; i < 25; i++)
  {
    if (i < 5)
      testN = 1;
    else
      testN = nextRnd(20, 30);
    testT = nextRnd(1, 50);
    testD = nextRnd(1, 50);
    int dd = nextRnd(0, 3);
    lineTest(dx[dd], dy[dd]);
    jumpTest(randomPath());
  }
  for (int i = 0; i < 3; i++)
  {
    testN = 100;
    testT = 100;
    testD = 100;
    randomTest(randomPath());
    testT = nextRnd(1, 100);
    testD = nextRnd(1, 100);
    randomTest(randomPath());
    testN--;
    jumpTest(randomPath());
  }
  return 0;
}

