#include <bits/stdc++.h>
using namespace std;
vector<int> v[5004];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, cnt = 1;
    cin >> n;
    int l, r[n + 1], ans[n + 1], maxin = 1;
    for (int i = 1; i <= 5000; i++) v[i].clear();
    for (int i = 1; i <= n; i++) {
      cin >> l >> r[i];
      v[l].push_back(i);
      if (l > maxin) maxin = l;
    }
    for (int i = 1; i <= maxin; i++) {
      int temp = v[i].size();
      cnt = max(cnt, i);
      for (int j = 0; j < temp; j++) {
        if (cnt <= r[v[i][j]]) {
          ans[v[i][j]] = cnt;
          cnt++;
        } else
          ans[v[i][j]] = 0;
      }
    }
    for (int i = 1; i <= n; i++) {
      if (i == n)
        cout << ans[i] << endl;
      else
        cout << ans[i] << " ";
    }
  }
}
