#include <bits/stdc++.h>
using namespace std;
struct work {
  int s, d, e;
  work(int s = 0, int d = 0, int e = 0) : s(s), d(d), e(e) {}
  bool operator<(const work b) const { return e < b.e; }
};
vector<work> v;
bool check(int s, int d) {
  int e = s + d - 1;
  int len = v.size();
  for (int i = 0; i < len; i++) {
    if (s >= v[i].s && s <= v[i].e) return false;
    if (e >= v[i].s && e <= v[i].e) return false;
    if (s <= v[i].s && e >= v[i].e) return false;
  }
  return true;
}
work change(int s, int d) {
  int e = s + d - 1;
  int len = v.size();
  if (check(1, d)) return work(1, d, 1 + d - 1);
  sort(v.begin(), v.end());
  for (int i = 0; i < len; i++) {
    if (check(v[i].e + 1, d)) return work(v[i].e + 1, d, v[i].e + d);
  }
}
int main() {
  int n;
  cin >> n;
  int s, d;
  for (int i = 0; i < n; i++) {
    cin >> s >> d;
    if (check(s, d))
      v.push_back(work(s, d, s + d - 1));
    else
      v.push_back(change(s, d));
    cout << v[v.size() - 1].s << ' ' << v[v.size() - 1].e << endl;
  }
}
