#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<long long int, long long int> > clients, answer, true_answer;
int main() {
  cin >> n;
  clients.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> clients[i].first >> clients[i].second;
  }
  answer.push_back(make_pair(0, 0));
  for (int i = 0; i < n; i++) {
    bool found = false;
    if (clients[i].first > answer.back().second) {
      found = true;
      answer.push_back(make_pair(clients[i].first,
                                 clients[i].first + clients[i].second - 1));
      true_answer.push_back(answer.back());
    }
    for (int j = 1; j < answer.size(); j++) {
      if ((answer.size() == 1 ||
           (answer[j].first > clients[i].first + clients[i].second - 1 &&
            answer[j - 1].second < clients[i].first)) &&
          !found) {
        answer.push_back(make_pair(clients[i].first,
                                   clients[i].first + clients[i].second - 1));
        true_answer.push_back(answer.back());
        found = true;
      }
    }
    for (int j = 0; j < answer.size() - 1; j++) {
      if (answer[j + 1].first - answer[j].second - 1 >= clients[i].second &&
          !found) {
        answer.push_back(make_pair(answer[j].second + 1,
                                   answer[j].second + clients[i].second));
        true_answer.push_back(answer.back());
        found = true;
      }
    }
    if (!found) {
      answer.push_back(make_pair(answer.back().second + 1,
                                 answer.back().second + clients[i].second));
      true_answer.push_back(answer.back());
    }
    sort(answer.begin(), answer.end());
  }
  for (auto p : true_answer) {
    cout << p.first << ' ' << p.second << endl;
  }
  return 0;
}
