#include <bits/stdc++.h>
using namespace std;
const int MX = 1e3 + 10;
int n, m, tmp, t, l[MX], r[MX];
int main() {
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> n;
    int tmp = 1;
    int p = 0;
    for (int j = 0; j < n; j++) {
      cin >> l[j] >> r[j];
      if (p == 0) {
        tmp = max(l[j], tmp);
      }
      if (l[j] <= tmp) {
        if (p == 0) {
          if (r[j] >= tmp) {
            cout << tmp << " ";
            tmp++;
          } else {
            cout << 0 << " ";
          }
        } else {
          p++;
        }
      }
      cout << endl;
    }
  }
}
