#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1, i = 0, j = 0, k = 0;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    long long int l[n], r[n];
    for (i = 0; i < n; ++i) cin >> l[i] >> r[i];
    long long int t = 0;
    for (i = 0; i < n; ++i) {
      ++t;
    sg:
      if (i < n) {
        if (r[i] > t - 1 && l[i] <= t)
          cout << t << " ";
        else if (r[i] > t - 1) {
          cout << l[i] << " ";
          t = l[i];
        } else {
          cout << "0 ";
          ++i;
          goto sg;
        }
      }
    }
    cout << "\n";
  }
  return 0;
}
