#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int N = 100010;
struct SCHEDULE {
  int id, x, y;
  SCHEDULE() {}
  SCHEDULE(int _id, int _x, int _y) : id(_id), x(_x), y(_y) {}
  bool operator<(const SCHEDULE s) const { return x < s.x; }
};
int main(void) {
  int n;
  scanf("%d", &n);
  vector<SCHEDULE> schedule;
  schedule.push_back(SCHEDULE(-1, 0, 0));
  for (int i = 0; i < n; i++) {
    sort(schedule.begin(), schedule.end());
    int s, d;
    scanf("%d %d", &s, &d);
    bool f = true;
    for (int j = 0; j < schedule.size(); j++) {
      if (!(schedule[j].y < s or s + d - 1 < schedule[j].x)) f = false;
    }
    if (f) {
      schedule.push_back(SCHEDULE(i, s, s + d - 1));
      continue;
    }
    for (int j = 1; j < schedule.size(); j++) {
      int duration = schedule[j].x - schedule[j - 1].y - 1;
      if (duration >= d) {
        schedule.push_back(
            SCHEDULE(i, schedule[j - 1].y + 1, schedule[j - 1].y + 1 + d - 1));
        f = true;
        break;
      }
    }
    if (f) continue;
    schedule.push_back(
        SCHEDULE(i, schedule[i].y + 1, schedule[i].y + 1 + d - 1));
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < schedule.size(); j++) {
      if (schedule[j].id == i) {
        printf("%d %d\n", schedule[j].x, schedule[j].y);
        break;
      }
    }
  }
  return 0;
}
