#include <bits/stdc++.h>
using namespace std;
typedef struct ans {
  int begin, end;
  int length;
} Ans;
int main() {
  int n;
  scanf("%d", &n);
  Ans ans[n];
  for (int i = 0; i < n; i++) {
    int flag = 0;
    int a, b;
    cin >> a >> b;
    for (int j = 0; j < i; j++) {
      if ((ans[j].begin <= a && ans[j].end >= a) ||
          (ans[j].begin <= a + b - 1 && ans[j].end >= a + b - 1) ||
          (ans[j].begin > a && ans[j].end < a + b - 1)) {
        flag = 1;
        break;
      }
    }
    if (flag == 0) {
      ans[i].begin = a;
      ans[i].end = a + b - 1;
    } else {
      int flag1 = 1;
      int j = 1;
      for (j = 1; flag1;) {
        flag1 = 0;
        for (int k = 0; k < i; k++) {
          if ((j >= ans[k].begin && j <= ans[k].end) ||
              (j + b - 1 >= ans[k].begin && j + b - 1 <= ans[k].end) ||
              (j < ans[k].begin && j + b - 1 > ans[k].end)) {
            flag1 = 1;
            j = min(ans[k].end + 1, j + b);
            break;
          }
        }
      }
      ans[i].begin = j;
      ans[i].end = j + b - 1;
    }
  }
  for (int i = 0; i < n; i++) {
    printf("%d %d\n", ans[i].begin, ans[i].end);
  }
}
