#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;
typedef vector<int> vi;
int main(){
int t;
cin>>t;
for(int testcase=0; testcase<t; testcase++){
int n; cin>>n;
vector<pair<int, int>> v(n);
map<pair<int, int>, int> m;
for (int i = 0; i < n; i++)
{
cin>>v[i].first>>v[i].second;
m[v[i]]++;
}
vector<pair<int, int>> l;
vector<pair<int, int>> r;
for(int i=0; i<v.size(); i++){
l.push_back({v[i].first, i});
r.push_back({v[i].second, i});
}
sort(l.begin(), l.end(), [](pair<int, int> a, pair<int, int> b){
return a.first < b.first;
});
sort(r.begin(), r.end(), [](pair<int, int> a, pair<int, int> b){
return a.first > b.first;
});
vi R(n);
vi L(n);
set<int> predictor;
for(auto item:l){
auto it = predictor.lower_bound(v[item.second].second);
if(it!=predictor.end()){
R[item.second] = *it;
}
predictor.insert(v[item.second].second);
}
// cout<<"theend";
predictor.clear();
for(auto item:r){
auto it = predictor.upper_bound(v[item.second].first);
if(it!=predictor.end()){
L[item.second] = *prev(it);
}
predictor.insert(v[item.second].first);
}
for (int i = 0; i < n; i++) {
int res;
if (m[v[i]] >= 2) {
res = 0;
} else {
res = R[i] - L[i] - (v[i].second - v[i].first);
// res = R[i];
}
cout<<res<<endl;
}
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+IAogCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiAKI2RlZmluZSBlbmRsICJcbiIgCnR5cGVkZWYgbG9uZyBsb25nIGludCBsbDsKdHlwZWRlZiB2ZWN0b3I8aW50PiB2aTsKCgppbnQgbWFpbigpewogICAgaW50IHQ7CiAgICBjaW4+PnQ7CiAgICAKICAgIGZvcihpbnQgdGVzdGNhc2U9MDsgdGVzdGNhc2U8dDsgdGVzdGNhc2UrKyl7CiAgICAgICAgaW50IG47IGNpbj4+bjsKCiAgICAgICAgdmVjdG9yPHBhaXI8aW50LCBpbnQ+PiB2KG4pOwogICAgICAgIG1hcDxwYWlyPGludCwgaW50PiwgaW50PiBtOwogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKQogICAgICAgIHsKICAgICAgICAgICAgY2luPj52W2ldLmZpcnN0Pj52W2ldLnNlY29uZDsKICAgICAgICAgICAgbVt2W2ldXSsrOwogICAgICAgIH0KICAgICAgICAKICAgICAgICB2ZWN0b3I8cGFpcjxpbnQsIGludD4+IGw7CiAgICAgICAgdmVjdG9yPHBhaXI8aW50LCBpbnQ+PiByOwoKICAgICAgICBmb3IoaW50IGk9MDsgaTx2LnNpemUoKTsgaSsrKXsKICAgICAgICAgICAgbC5wdXNoX2JhY2soe3ZbaV0uZmlyc3QsIGl9KTsKICAgICAgICAgICAgci5wdXNoX2JhY2soe3ZbaV0uc2Vjb25kLCBpfSk7CiAgICAgICAgfQoKICAgICAgICBzb3J0KGwuYmVnaW4oKSwgbC5lbmQoKSwgW10ocGFpcjxpbnQsIGludD4gYSwgcGFpcjxpbnQsIGludD4gYil7CiAgICAgICAgICAgIHJldHVybiBhLmZpcnN0IDwgYi5maXJzdDsKICAgICAgICB9KTsKCiAgICAgICAgCiAgICAgICAgc29ydChyLmJlZ2luKCksIHIuZW5kKCksIFtdKHBhaXI8aW50LCBpbnQ+IGEsIHBhaXI8aW50LCBpbnQ+IGIpewogICAgICAgICAgICByZXR1cm4gYS5maXJzdCA+IGIuZmlyc3Q7CiAgICAgICAgfSk7CgogICAgICAgIHZpIFIobik7CiAgICAgICAgdmkgTChuKTsKCiAgICAgICAgc2V0PGludD4gcHJlZGljdG9yOwogICAgICAgIGZvcihhdXRvIGl0ZW06bCl7CiAgICAgICAgICAgIGF1dG8gaXQgPSBwcmVkaWN0b3IubG93ZXJfYm91bmQodltpdGVtLnNlY29uZF0uc2Vjb25kKTsKCiAgICAgICAgICAgIGlmKGl0IT1wcmVkaWN0b3IuZW5kKCkpewogICAgICAgICAgICAgICAgUltpdGVtLnNlY29uZF0gPSAqaXQ7CiAgICAgICAgICAgIH0KCiAgICAgICAgICAgIHByZWRpY3Rvci5pbnNlcnQodltpdGVtLnNlY29uZF0uc2Vjb25kKTsKICAgICAgICB9CgogICAgICAgIC8vIGNvdXQ8PCJ0aGVlbmQiOwoKICAgICAgICBwcmVkaWN0b3IuY2xlYXIoKTsKICAgICAgICBmb3IoYXV0byBpdGVtOnIpewogICAgICAgICAgICBhdXRvIGl0ID0gcHJlZGljdG9yLnVwcGVyX2JvdW5kKHZbaXRlbS5zZWNvbmRdLmZpcnN0KTsKCiAgICAgICAgICAgIGlmKGl0IT1wcmVkaWN0b3IuZW5kKCkpewogICAgICAgICAgICAgICAgTFtpdGVtLnNlY29uZF0gPSAqcHJldihpdCk7CiAgICAgICAgICAgIH0KCiAgICAgICAgICAgIHByZWRpY3Rvci5pbnNlcnQodltpdGVtLnNlY29uZF0uZmlyc3QpOwogICAgICAgIH0KCiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIHsKICAgICAgICAgICAgaW50IHJlczsKICAgICAgICAgICAgaWYgKG1bdltpXV0gPj0gMikgewogICAgICAgICAgICAgICAgcmVzID0gMDsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHJlcyA9IFJbaV0gLSBMW2ldIC0gKHZbaV0uc2Vjb25kIC0gdltpXS5maXJzdCk7CiAgICAgICAgICAgICAgICAvLyByZXMgPSBSW2ldOwogICAgICAgICAgICB9CiAgICAgICAgICAgIAogICAgICAgICAgICBjb3V0PDxyZXM8PGVuZGw7CiAgICAgICAgfQogICAgICAgICAgICAKICAgIH0KCiAgICByZXR1cm4gMDsKfQ==