#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define rep(Ii,Jj,Kk) for(int Ii=(Jj),Ii##_=(Kk);Ii<=Ii##_;Ii++)
#define per(Ii,Jj,Kk) for(int Ii=(Jj),Ii##_=(Kk);Ii>=Ii##_;Ii--)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned uint;
typedef long double db;
#define fir first
#define sec second
#define siz(Aa) ((int)(Aa).size())
#define all(Aa) (Aa).begin(),(Aa).end()
#define ckmx(Aa,Bb) (Aa=max(Aa,Bb))
#define ckmn(Aa,Bb) (Aa=min(Aa,Bb))
void eachT();
signed main(){ios::sync_with_stdio(false),cin.tie(nullptr);
int T;cin>>T;
while(T--)eachT();
return 0;}
/*
*/
void eachT() {
int n;
cin >> n;
vector<vector<int>> v(n + 2);
for (int i = 0; i < n; ++i) {
int l, r;
cin >> l >> r;
v[l].push_back(r);
}
bool ok = 1;
// int cnt=0;
for (int l = 1; l <= n; ++l) {
if (v[l].empty()) {
ok = 0;
break;
}
sort(v[l].begin(), v[l].end(), greater<>());
int big = v[l][0];
for (int j = 1; j < v[l].size(); ++j) {
if (v[l][j - 1] == v[l][j]) {
ok = 0;
break;
}
int r = v[l][j];
v[r + 1].push_back(big);
// cnt++;
}
if (ok == 0) break;
}
cout << ok << '\n';
// cerr<<cnt<<endl;
}