#include <bits/stdc++.h>
using namespace std;
set<pair<long long, long long> > interval;
int main() {
  int n;
  cin >> n;
  interval.insert(pair<long long, long long>(0, -1));
  interval.insert(pair<long long, long long>(1, 100000000000000000LL));
  while (n--) {
    long long a, b;
    cin >> a >> b;
    pair<long long, long long> k;
    for (set<pair<long long, long long> >::reverse_iterator it =
             interval.rbegin();
         it != interval.rend(); it++) {
      if (it->first <= a) {
        k = *it;
        break;
      }
    }
    if (k.second >= a + b - 1) {
      interval.erase(k);
      cout << a << ' ' << a + b - 1 << endl;
      if (k.first != a)
        interval.insert(pair<long long, long long>(k.first, a - 1));
      if (k.second != a + b - 1)
        interval.insert(pair<long long, long long>(a + b, k.second));
    } else {
      for (set<pair<long long, long long> >::iterator it = interval.begin();
           it != interval.end(); it++) {
        if (it->second - it->first >= b - 1) {
          k = *it;
          break;
        }
      }
      interval.erase(k);
      a = k.first, b = k.first + b - 1;
      cout << a << ' ' << b << endl;
      if (k.first != a)
        interval.insert(pair<long long, long long>(k.first, a - 1));
      if (k.second != b)
        interval.insert(pair<long long, long long>(b + 1, k.second));
    }
  }
  return 0;
}
