#include <bits/stdc++.h>
using namespace std;
int n, m;
pair<int, int> answer[404];
set<pair<int, int> > S;
set<pair<int, int> >::iterator it, ii;
bool check(pair<int, int> c) {
  ii = S.lower_bound(make_pair(c.first, 0));
  if (ii != S.end()) {
    if (c.first + c.second > (*ii).first) return false;
  }
  if (ii != S.begin()) {
    ii--;
    if (c.first < (*ii).first + (*ii).second) return false;
  }
  return true;
}
int main() {
  scanf("%d", &n);
  S.insert(make_pair(0, 1));
  for (int i = 0; i < n; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    pair<int, int> c = make_pair(x, y);
    if (check(c)) {
      answer[i] = c;
      S.insert(c);
      continue;
    }
    for (it = S.begin(); it != S.end(); it++) {
      c = make_pair((*it).first + (*it).second, y);
      if (check(c)) {
        S.insert(c);
        answer[i] = c;
        break;
      }
    }
  }
  for (int i = 0; i < n; ++i)
    printf("%d %d\n", answer[i].first, answer[i].second + answer[i].first - 1);
}
