#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1007;
struct Time {
  long long s, t;
  Time() {}
  Time(long long _s, long long _t) { s = _s, t = _t; }
  bool in(long long a, long long b) {
    if (s <= a && b <= t) return 1;
    return 0;
  }
  long long len() { return t - s + 1; }
};
vector<Time> tmm;
Time res[MAXN];
int main() {
  int n;
  cin >> n;
  tmm.push_back(Time(1ll, 2000000007ll));
  for (int i = 1; i <= n; i++) {
    long long a, b;
    cin >> a >> b;
    b += a;
    b--;
    bool fl = 0;
    for (int j = 0; j < tmm.size(); j++) {
      if (tmm[j].in(a, b)) {
        fl = 1;
        long long k = tmm[j].t;
        tmm[j].t = a - 1;
        res[i] = Time(a, b);
        tmm.insert(tmm.begin() + j + 1, Time(b + 1, k));
        break;
      }
    }
    if (fl == 0) {
      for (int j = 0; j < tmm.size(); j++) {
        if (tmm[j].len() >= b - a + 1) {
          res[i] = Time(tmm[j].s, tmm[j].s + b - a);
          tmm[j].s = tmm[j].s + b - a + 1;
          break;
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << res[i].s << ' ' << res[i].t << endl;
  }
  return 0;
}
