#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  vector<long long int> s, d;
  for (long long int i = 0; i < n; i++) {
    long long int S;
    cin >> S;
    long long int D;
    cin >> D;
    s.push_back(S);
    d.push_back(D);
  }
  set<pair<long long int, long long int>> done;
  map<long long int, long long int> ans;
  for (long long int i = 0; i < n; i++) {
    if (!i) {
      done.insert({s[i], d[i]});
      ans[i] = s[i];
      continue;
    }
    auto next = done.lower_bound({s[i], -1});
    bool ok = true;
    if (next != done.end()) ok &= s[i] + d[i] - 1 < next->first;
    if (next != done.begin()) {
      next--;
      ok &= next->first + next->second - 1 < s[i];
    }
    if (ok) {
      done.insert({s[i], d[i]});
      ans[i] = s[i];
      continue;
    }
    if (d[i] < done.begin()->first - 1) {
      done.insert({1, d[i]});
      ans[i] = 1;
      continue;
    }
    long long int F = -1, S = -1;
    for (auto g : done) {
      auto next = done.upper_bound(g);
      if (next == done.end() or g.first + g.second + d[i] - 1 < (*next).first) {
        F = g.first + g.second;
        break;
      }
    }
    if (~F) {
      done.insert({F, d[i]});
      ans[i] = F;
    }
  }
  for (long long int i = 0; i < n; i++)
    cout << ans[i] << " " << ans[i] + d[i] - 1 << '\n';
}
