#include <bits/stdc++.h>
using namespace std;
enum { MAX = 2100000000 };
set<pair<int, int> > book;
int main() {
  book.insert(pair<int, int>(1, MAX));
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int s, d;
    scanf("%d%d", &s, &d);
    auto it = book.begin();
    bool found = 0;
    while (it != book.end()) {
      if (it->first > s) break;
      if (it->second >= std::max(s, it->first) + d - 1) {
        int b = (s < it->first) ? (it->first) : s;
        if (s > it->first) {
          book.insert(pair<int, int>(it->first, s - 1));
        }
        if (b - it->first + d < it->second) {
          book.insert(pair<int, int>(b + d, it->second));
        }
        printf("%d %d\n", b, b + d - 1);
        book.erase(it);
        found = 1;
        break;
      }
      ++it;
    }
    it = book.begin();
    s = 0;
    while (!found && it != book.end()) {
      if (it->second >= std::max(s, it->first) + d - 1) {
        int b = (s < it->first) ? (it->first) : s;
        if (s > it->first) {
          book.insert(pair<int, int>(it->first, s - 1));
        }
        if (b - it->first + d < it->second) {
          book.insert(pair<int, int>(b + d, it->second));
        }
        printf("%d %d\n", b, b + d - 1);
        book.erase(it);
        found = 1;
        break;
      }
      ++it;
    }
  }
  return 0;
}
