#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    queue<pair<int, int> > q;
    int l, r;
    pair<int, int> p;
    for (int i = 0; i < n; ++i) {
      cin >> l >> r;
      p = {l, r};
      q.push(p);
    }
    int time = 0;
    while (!q.empty()) {
      time++;
      if (q.front().first <= time && q.front().second >= time) {
        cout << time << " ";
        q.pop();
      } else if (q.front().second <= time) {
        cout << 0 << " ";
        q.pop();
        time--;
      }
    }
    cout << endl;
  }
  return 0;
}
