#include <bits/stdc++.h>
using namespace std;
vector<string> vec_splitter(string s) {
  for (char& c : s) c = c == ',' ? ' ' : c;
  stringstream ss;
  ss << s;
  vector<string> res;
  for (string z; ss >> z; res.push_back(z))
    ;
  return res;
}
void debug_out(vector<string> args, int idx) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, Head H, Tail... T) {
  if (idx > 0) cerr << ", ";
  stringstream ss;
  ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, T...);
}
long long int power(long long int b, long long int e) {
  if (e == 0) return 1;
  if (e % 2 == 1)
    return b * power(b * b, (e - 1) / 2);
  else
    return power(b * b, e / 2);
}
long long int power(long long int b, long long int e, long long int m) {
  if (e == 0) return 1;
  if (e % 2 == 1)
    return b * power(((b % m) * (b % m)) % m, (e - 1) / 2, m) % m;
  else
    return power(((b % m) * (b % m)) % m, e / 2, m) % m;
}
int nDig(long long int n) {
  if (n < 0) n *= -1;
  if (n == 0) return 1;
  return floor(log10(n) + 1);
}
void swagWaalaFunction() {
  long long int n, li, ri, k = INT_MAX;
  cin >> n;
  long long int arr[n];
  memset(arr, 0, sizeof(arr));
  ;
  vector<pair<pair<long long int, long long int>, long long int>> v;
  set<long long int> s;
  for (long long int i = 0; i < n; i++) {
    cin >> li >> ri;
    v.push_back({{li, i}, ri});
    k = min(k, li);
  }
  sort(v.begin(), v.end());
  for (long long int i = 0; i < n; i++) {
    if (v[i].second < k)
      arr[v[i].first.second] = 0;
    else {
      if (s.count(max(v[i].first.first, k)) == 0)
        arr[v[i].first.second] = max(v[i].first.first, k),
        s.insert(max(v[i].first.first, k)), k++;
      else if (s.count(max(v[i].first.first, k)) == 1 and
               *s.rbegin() + 1 <= v[i].second and s.count(*s.rbegin() + 1) == 0)
        arr[v[i].first.second] = *s.rbegin() + 1, s.insert(*s.rbegin() + 1),
        k += 2;
      else if (s.count(max(v[i].first.first, k)) == 1)
        arr[v[i].first.second] = 0, k++;
    }
  }
  for (long long int i = 0; i < n; i++) cout << arr[i] << " ";
  cout << '\n';
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int t = 1;
  cin >> t;
  while (t--) swagWaalaFunction();
  return 0;
}
