#include <bits/stdc++.h>
using namespace std;
struct period {
  long long start, len;
} ps[1000];
int np;
int main() {
  long long i, first, fit, n, a, b, firstp;
  cin >> n;
  np = 1;
  ps[1].start = 1;
  ps[1].len = 210000000000000LL;
  for (int task = 1; task <= n; task++) {
    cin >> a >> b;
    firstp = 0;
    fit = 0;
    first = 210000000000000LL;
    for (i = 1; i <= np; i++) {
      if (first >= ps[i].start && ps[i].len >= b) {
        first = ps[i].start;
        firstp = i;
      }
      if (ps[i].start <= a && ps[i].start + ps[i].len >= a + b) fit = i;
    }
    if (fit) {
      if (ps[fit].start == a) {
        ps[fit].start += b;
        ps[fit].len -= b;
      } else if (ps[fit].len + ps[fit].start == a + b) {
        ps[fit].len -= b;
      } else {
        if (a + b < ps[fit].len + ps[fit].start) {
          np++;
          ps[np].start = a + b;
          ps[np].len = ps[fit].len + ps[fit].start - a - b;
        }
        ps[fit].len = a - ps[fit].start;
      }
      printf("%I64d %I64d\n", a, a + b - 1);
    } else {
      printf("%I64d %I64d\n", ps[firstp].start, ps[firstp].start + b - 1);
      ps[firstp].start += b;
      ps[firstp].len -= b;
    }
  }
}
