#include <bits/stdc++.h>
template <typename T>
void wap(T &a, T &b) {
  T c = a;
  a = b;
  b = c;
}
using namespace std;
vector<pair<long long, long long>> seg, ans;
long long n, x[200], y[200];
int main() {
  ios::sync_with_stdio(0);
  seg.emplace_back(1, 1e15);
  cin >> n;
  for (long long i = 0; i < n; ++i) {
    cin >> x[i] >> y[i];
    vector<pair<long long, long long>> newseg;
    sort(begin(seg), end(seg));
    long long okay = -1;
    for (long long j = 0; j < seg.size(); ++j) {
      auto l = seg[j].first, r = seg[j].second;
      if (x[i] >= l && x[i] + y[i] - 1 <= r) {
        if (x[i] > l) {
          newseg.emplace_back(l, x[i] - 1);
        }
        if (x[i] + y[i] - 1 < r) {
          newseg.emplace_back(x[i] + y[i], r);
        }
        ans.emplace_back(x[i], x[i] + y[i] - 1);
        okay = j;
        break;
      }
    }
    if (okay >= 0) {
      for (long long j = 0; j < seg.size(); ++j) {
        if (j != okay) {
          newseg.push_back(seg[j]);
        }
      }
      seg = newseg;
      continue;
    }
    for (long long j = 0; j < seg.size(); ++j) {
      auto l = seg[j].first, r = seg[j].second;
      if (r - l + 1 >= y[i]) {
        if (l + y[i] - 1 < r) {
          newseg.emplace_back(l + y[i], r);
        }
        ans.emplace_back(l, l + y[i] - 1);
        okay = j;
        break;
      }
    }
    if (okay >= 0) {
      for (long long j = 0; j < seg.size(); ++j) {
        if (j != okay) {
          newseg.push_back(seg[j]);
        }
      }
      seg = newseg;
      continue;
    }
  }
  for (auto e : ans) {
    cout << e.first << " " << e.second << "\n";
  }
}
