#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, leave = 1, l, r;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> l >> r;
      if (l > leave) leave = l;
      if (leave <= r) {
        cout << leave << " ";
        leave++;
      } else
        cout << 0 << " ";
      cout << endl;
    }
  }
}
