#include <bits/stdc++.h>
using namespace std;
int x[1000], y[1000], n, a, l, b;
int main() {
  scanf("%d", &n);
  l = 1;
  x[1] = 1, y[1] = 2000000000;
  ;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &a, &b);
    int j, t = 0;
    for (j = 1; j <= l; j++)
      if (a >= x[j] && a + b - 1 <= y[j]) {
        t = 1;
        break;
      }
    if (t) {
      cout << a << " " << a + b - 1 << endl;
      if (a > x[j] && a + b - 1 < y[j]) {
        l++;
        for (int p = l; p > j + 1; p--) x[p] = x[p - 1], y[p] = y[p - 1];
        y[j + 1] = y[j], y[j] = a - 1, x[j + 1] = a + b;
      } else {
        if (a == x[j]) x[j] = a + b;
        if (a + b - 1 == y[j]) y[j] = a - 1;
      }
    } else
      for (int j = 1; j <= l; j++)
        if (y[j] - x[j] + 1 >= b) {
          cout << x[j] << " " << x[j] + b - 1 << endl;
          x[j] = x[j] + b;
          break;
        }
  }
  return 0;
}
