#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<pair<long long, long long>> requests;
  vector<pair<long long, long long>> cur;
  vector<pair<long long, long long>> ans(n);
  for (long long i = 0; i < n; ++i) {
    long long s, d;
    cin >> s >> d;
    requests.emplace_back(s, d);
  }
  for (long long i = 0; i < n; ++i) {
    long long s = requests[i].first;
    long long e = s + requests[i].second - 1;
    bool notConflict = true;
    for (long long j = 0; j < cur.size(); ++j) {
      if (((cur[j].first <= s && cur[j].second >= s) ||
           (cur[j].first <= e && cur[j].second >= e)) ||
          ((s <= cur[j].first && e >= cur[j].first) ||
           (s <= cur[j].second && e >= cur[j].second))) {
        notConflict = false;
      }
    }
    if (notConflict) {
      ans[i] = make_pair(s, e);
      cur.emplace_back(s, e);
    } else {
      sort(cur.begin(), cur.end());
      bool find = false;
      if (!cur.empty() && cur[0].first > requests[i].second) {
        ans[i] = make_pair(1, requests[i].second);
        find = true;
      } else if (cur.size() > 1) {
        for (long long j = 0; j < cur.size() - 1; ++j) {
          long long d = cur[j + 1].first - cur[j].second - 1;
          if (d >= requests[i].second) {
            ans[i] = make_pair(cur[j].second + 1,
                               cur[j].second + requests[i].second);
            find = true;
            break;
          }
        }
      }
      if (!find && !cur.empty()) {
        ans[i] = make_pair(cur.back().second + 1,
                           cur.back().second + requests[i].second);
      }
      cur.push_back(ans[i]);
    }
  }
  for (long long i = 0; i < n; ++i) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }
  return 0;
}
