#include <bits/stdc++.h>
using namespace std;
struct req {
  long long s, e;
} reqs[300];
bool operator<(req a, req b) { return a.s < b.s; }
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    sort(reqs, reqs + i);
    int s, t;
    cin >> s >> t;
    bool flag = true;
    for (int j = 0; j < i; j++) {
      if ((reqs[j].s <= s && reqs[j].e >= s) ||
          (reqs[j].s >= s && reqs[j].s <= s + t - 1)) {
        flag = false;
        break;
      }
    }
    if (flag) {
      reqs[i].s = s;
      reqs[i].e = s + t - 1;
      cout << reqs[i].s << " " << reqs[i].e << endl;
    } else {
      if (t < reqs[0].s) {
        reqs[i].s = 1;
        reqs[i].e = t;
        cout << reqs[i].s << " " << reqs[i].e << endl;
      } else {
        bool mark = false;
        for (int j = 0; j < i - 1; j++) {
          if (reqs[j + 1].s - reqs[j].e - 1 >= t) {
            reqs[i].s = reqs[j].e + 1;
            reqs[i].e = reqs[j].e + t;
            cout << reqs[i].s << " " << reqs[i].e << endl;
            mark = true;
            break;
          }
        }
        if (!mark) {
          reqs[i].s = reqs[i - 1].e + 1;
          reqs[i].e = reqs[i - 1].e + t;
          cout << reqs[i].s << " " << reqs[i].e << endl;
        }
      }
    }
  }
}
