#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
inline int Gcd(int X, int Y) { return Y ? Gcd(Y, X % Y) : X; }
inline long long Gcd(long long X, long long Y) { return Y ? Gcd(Y, X % Y) : X; }
inline int Max(int X, int Y) { return X < Y ? Y : X; }
inline int Min(int X, int Y) { return X < Y ? X : Y; }
inline long long Max(long long X, long long Y) { return X < Y ? Y : X; }
inline long long Min(long long X, long long Y) { return X < Y ? X : Y; }
inline int Pow(int base, long long exp, int _mod) {
  int _ans = 1;
  for (; exp; exp >>= 1, base = (long long)base * base % _mod)
    exp& 1 ? _ans = (long long)_ans * base % _mod : 0;
  return _ans;
}
inline long long Pow(long long base, long long exp, long long _mod) {
  long long _ans = 1;
  for (; exp; exp >>= 1, base = base * base % _mod)
    exp& 1 ? _ans = _ans * base % _mod : 0;
  return _ans;
}
int n, q;
int l[100001], r[100001], Ans[10001];
int que[100001], L, R;
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    L = 1, R = 0;
    scanf("%d", &n);
    memset(Ans, 0, sizeof Ans);
    for (int i = (1); i <= (n); ++i) scanf("%d%d", l + i, r + i);
    int i = 1;
    for (int t = (1); t <= (5000); ++t) {
      while (l[i] == t) que[++R] = i, ++i;
      while (L <= R && r[que[L]] < t) ++L;
      if (L <= R) Ans[que[L++]] = t;
    }
    for (int j = (1); j <= (n); ++j) printf("%d ", Ans[j]);
    puts("");
  }
  return 0;
}
