#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
int main() {
  signed long long int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<pair<int, int> > vs(n);
    for (int i = 0; i < n; i++) {
      cin >> vs[i].first >> vs[i].second;
    }
    int dep[n];
    dep[0] = (vs[0].first) + 1;
    int ans[n];
    ans[0] = vs[0].first;
    for (int i = 1; i < n; i++) {
      int ar = vs[i].first;
      if (vs[i].second >= dep[i - 1] && ans[i - 1] != 0) {
        if (ar <= dep[i - 1]) {
          dep[i] = dep[i - 1] + 1;
          ans[i] = dep[i - 1];
        } else {
          ans[i] = ar;
          dep[i] = ar + 1;
        }
      } else if (vs[i].second < dep[i - 1]) {
        dep[i] = vs[i].second;
        ans[i] = 0;
      } else if (vs[i].second >= dep[i - 1] && ans[i - 1] == 0) {
        signed long long int j = i - 1;
        while (ans[j] == 0 && j >= 0) {
          j--;
        }
        if (j >= 0 && vs[i].second >= dep[j]) {
          if (ar <= dep[j]) {
            dep[i] = dep[j] + 1;
            ans[i] = dep[j];
          } else {
            ans[i] = ar;
            dep[i] = ar + 1;
          }
        } else {
          ans[i] = 0;
          dep[i] = vs[i].second;
        }
      }
    }
    for (int i = 0; i < n; i++) {
      cout << ans[i] << " ";
    }
    cout << "\n";
  }
  return 0;
}
