#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);
  vector<pair<long long, long long>> used;
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    long long a, b;
    cin >> a >> b;
    auto it = used.begin();
    while (it != used.end() && it->second <= a) it++;
    if (it != used.end() && it->first < a + b) {
      it = used.begin();
      if (it->first >= b + 1) {
        cout << 1 << " " << b << "\n";
        used.insert(used.begin(), {1, b + 1});
      } else {
        while (next(it) != used.end() && next(it)->first - it->second < b) it++;
        cout << it->second << " " << it->second + b - 1 << "\n";
        used.insert(next(it), {it->second, it->second + b});
      }
    } else {
      cout << a << " " << a + b - 1 << "\n";
      used.insert(it, {a, a + b});
    }
  }
  return 0;
}
