#include <bits/stdc++.h>
using namespace std;
int main() {
  set<long long> a, b;
  b.insert(-1), a.insert(0), b.insert(0), a.insert((long long)10000000000);
  long long n, x, y, cnt = 0;
  scanf("%lld", &n);
  while (n--) {
    scanf("%lld %lld", &x, &y);
    long long num = x + y - 1, flag = 0;
    auto px = a.begin();
    auto py = b.begin();
    while (px != a.end()) {
      int xx = *px;
      int yy = *py;
      px++;
      py++;
      if (yy < x && xx > num) {
        a.insert(x);
        b.insert(num);
        flag = 1;
        printf("%lld %lld\n", x, num);
        break;
      }
    }
    if (!flag) {
      auto px = a.begin();
      auto py = b.begin();
      while (px != a.end()) {
        long long xx = *px;
        long long yy = *py;
        px++;
        py++;
        if (xx - yy - 1 >= y) {
          a.insert(yy + 1);
          b.insert(yy + y);
          printf("%lld %lld\n", yy + 1, yy + y);
          break;
        }
      }
    }
  }
}
