#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 5;
const long long int inf64 = 1e18 + 5;
bool chk(pair<long long int, long long int> p,
         vector<pair<long long int, long long int> > &ans) {
  p.second = p.first + p.second - 1;
  for (pair<long long int, long long int> x : ans) {
    long long int mn = min(p.second, x.second);
    long long int mx = max(p.first, x.first);
    if (mn >= mx) return false;
  }
  return true;
}
vector<pair<long long int, long long int> > findpos(
    pair<long long int, long long int> p,
    vector<pair<long long int, long long int> > &ans) {
  vector<pair<long long int, long long int> > pos;
  for (pair<long long int, long long int> x : ans) {
    long long int st = x.second + 1;
    if (chk({st, p.second}, ans)) pos.push_back({st, st + p.second - 1});
  }
  return pos;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, i;
  cin >> n;
  vector<pair<long long int, long long int> > v(n);
  for (i = 0; i < n; i++) cin >> v[i].first >> v[i].second;
  vector<pair<long long int, long long int> > ans;
  ans.push_back({0, 0});
  for (i = 0; i < n; i++) {
    if (chk(v[i], ans))
      ans.push_back({v[i].first, v[i].first + v[i].second - 1});
    else {
      vector<pair<long long int, long long int> > pos = findpos(v[i], ans);
      sort(pos.begin(), pos.end());
      ans.push_back(pos[0]);
    }
  }
  for (int i = 1; i < ans.size(); i++)
    cout << ans[i].first << ' ' << ans[i].second << '\n';
}
