#include <bits/stdc++.h>
using namespace std;
struct node {
  long long start;
  long long vol;
  node *next;
};
node *head;
bool insert1(long long day, long long vol) {
  node *p = head->next, *q = head;
  while (p->start + p->vol < day) q = p, p = p->next;
  if (p->start > day) return false;
  if (p->start + p->vol >= day + vol) {
    if (p->start != day) {
      q->next = new node;
      q = q->next;
      q->start = p->start;
      q->vol = day - p->start;
    }
    if (p->start + p->vol > day + vol) {
      q->next = new node;
      q = q->next;
      q->start = day + vol;
      q->vol = p->start + p->vol - day - vol;
    }
    q->next = p->next;
    printf("%lld %lld\n", day, day + vol - 1);
    return true;
  } else
    return false;
}
void insert2(long long vol) {
  node *p = head->next, *q = head;
  while (p->vol < vol) q = p, p = p->next;
  q->next = new node;
  q = q->next;
  q->start = p->start + vol;
  q->vol = p->vol - vol;
  q->next = p->next;
  printf("%lld %lld\n", p->start, p->start + vol - 1);
  return;
}
int main() {
  int n;
  long long day, vol;
  scanf("%d", &n);
  node *p = new node;
  head = new node;
  head->next = p;
  p->start = 1;
  p->vol = 9999999999999ll;
  p->next = NULL;
  for (int i = 1; i <= n; ++i) {
    scanf("%lld %lld", &day, &vol);
    if (insert1(day, vol) == false) {
      insert2(vol);
    }
  }
  return 0;
}
