#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1073741824")
using namespace std;
using namespace placeholders;
const int inf = (int)1e9 + 9;
const long long linf = (long long)1e18;
const long double eps = 1e-7;
const int mod = (int)1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  srand(time(0));
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<pair<int, int> > kek(n);
    for (int i = 0; i < n; i++) {
      cin >> kek[i].first >> kek[i].second;
    }
    int time = 1, p = 0;
    list<int> q;
    vector<int> res(n);
    vector<bool> left(n, false);
    while (p != n || !q.empty()) {
      while (p < n && kek[p].first == time) {
        q.push_back(p);
        p++;
      }
      if (q.size()) {
        int i = q.front();
        q.pop_front();
        res[i] = time;
      }
      for (auto i : q) {
        if (kek[i].second == time) {
          left[i] = true;
        }
      }
      while (q.size() && left[q.front()]) {
        res[q.front()] = 0;
        q.pop_front();
      }
      time++;
    }
    for (auto i : res) {
      cout << i << " ";
    }
    cout << "\n";
  }
}
