#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  scanf("%lld", &n);
  pair<long long, long long> l[1000];
  set<pair<long long, long long> > v;
  long long u = 1;
  for (int i = 0; i < n; i++) {
    scanf("%lld %lld", &l[i].first, &l[i].second);
    u = 1;
    for (pair<long long, long long> j : v) {
      if (u >= j.first && u <= j.second) u = j.second + 1;
    }
    if (v.empty()) {
      printf("%lld %lld\n", l[i].first, l[i].first + l[i].second - 1);
      v.insert(
          pair<long long, long long>(l[i].first, l[i].first + l[i].second - 1));
      continue;
    }
    auto it = v.end();
    it--;
    if (l[i].first > it->second) {
      printf("%lld %lld\n", l[i].first, l[i].first + l[i].second - 1);
      v.insert(
          pair<long long, long long>(l[i].first, l[i].first + l[i].second - 1));
      continue;
    }
    bool f = 0;
    for (pair<long long, long long> j : v) {
      if ((l[i].first >= j.first && l[i].first <= j.second) ||
          (j.first >= l[i].first && j.first <= l[i].first + l[i].second - 1)) {
        f = 1;
        break;
      }
      if ((l[i].first + l[i].second - 1 >= j.first &&
           l[i].first + l[i].second - 1 <= j.second) ||
          (j.second >= l[i].first &&
           j.second <= l[i].first + l[i].second - 1)) {
        f = 1;
        break;
      }
    }
    if (f == 0) {
      printf("%lld %lld\n", l[i].first, l[i].first + l[i].second - 1);
      v.insert(
          pair<long long, long long>(l[i].first, l[i].first + l[i].second - 1));
      continue;
    }
    f = 0;
    long long at = u;
    for (pair<long long, long long> j : v) {
      if (at < j.first && at + l[i].second - 1 < j.first) {
        printf("%lld %lld\n", at, at + l[i].second - 1);
        v.insert(pair<long long, long long>(at, at + l[i].second - 1));
        f = 1;
        break;
      }
      at = j.second + 1;
    }
    if (!f) {
      printf("%lld %lld\n", at, at + l[i].second - 1);
      v.insert(pair<long long, long long>(at, at + l[i].second - 1));
    }
  }
  return 0;
}
