#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
struct Seg{
int l, r, index;
};
int main() {
cin.tie(0)->sync_with_stdio(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<Seg> seg(n);
vector<int> ans(n, 0);
for(int i = 0; i < n; i++){
cin >> seg[i].l >> seg[i].r;
seg[i].index = i;
}
sort(seg.begin(), seg.end(), [](const Seg& a, const Seg& b) {
if (a.l != b.l) return a.l < b.l;
return a.r > b.r;
});
set<int> r;
for(auto u: seg){
auto it = r.lower_bound(u.r);
if(it != r.end()) {
ans[u.index] += *it - u.r;
}
r.insert(u.r);
}
for(auto& u: seg){
u.r = - u.r;
u.l = - u.l;
swap(u.l, u.r);
}
sort(seg.begin(), seg.end(), [](const Seg& a, const Seg& b) {
if (a.l != b.l) return a.l < b.l;
return a.r > b.r;
});
set<int> l;
for(auto u: seg){
auto it = l.lower_bound(u.r);
if(it != l.end()) {
ans[u.index] += *it - u.r;
}
l.insert(u.r);
}
for(int i = 1; i < seg.size(); i++){
if(seg[i].l == seg[i-1].l && seg[i].r == seg[i-1].r){
ans[seg[i].index] = 0;
ans[seg[i-1].index] = 0;
}
}
for(auto u: ans){
cout << u << endl;
}
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8c2V0Pgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RydWN0IFNlZ3sKICAgIGludCBsLCByLCBpbmRleDsKfTsKCmludCBtYWluKCkgewogICAgY2luLnRpZSgwKS0+c3luY193aXRoX3N0ZGlvKDApOwogICAgaW50IHQ7CiAgICBjaW4gPj4gdDsKICAgIHdoaWxlICh0LS0pIHsKICAgICAgICBpbnQgbjsKICAgICAgICBjaW4gPj4gbjsKICAgICAgICB2ZWN0b3I8U2VnPiBzZWcobik7CiAgICAgICAgdmVjdG9yPGludD4gYW5zKG4sIDApOwogICAgICAgIGZvcihpbnQgaSA9IDA7IGkgPCBuOyBpKyspewogICAgICAgICAgICBjaW4gPj4gc2VnW2ldLmwgPj4gc2VnW2ldLnI7CiAgICAgICAgICAgIHNlZ1tpXS5pbmRleCA9IGk7CiAgICAgICAgfQogICAgICAgIHNvcnQoc2VnLmJlZ2luKCksIHNlZy5lbmQoKSwgW10oY29uc3QgU2VnJiBhLCBjb25zdCBTZWcmIGIpIHsKICAgICAgICAgICAgaWYgKGEubCAhPSBiLmwpIHJldHVybiBhLmwgPCBiLmw7CiAgICAgICAgICAgIHJldHVybiBhLnIgPiBiLnI7CiAgICAgICAgfSk7CgogICAgICAgIHNldDxpbnQ+IHI7CiAgICAgICAgZm9yKGF1dG8gdTogc2VnKXsKICAgICAgICAgICAgYXV0byBpdCA9IHIubG93ZXJfYm91bmQodS5yKTsKICAgICAgICAgICAgaWYoaXQgIT0gci5lbmQoKSkgewogICAgICAgICAgICAgICAgYW5zW3UuaW5kZXhdICs9ICppdCAtIHUucjsKICAgICAgICAgICAgfQogICAgICAgICAgICByLmluc2VydCh1LnIpOwogICAgICAgIH0KCiAgICAgICAgZm9yKGF1dG8mIHU6IHNlZyl7CiAgICAgICAgICAgIHUuciA9IC0gdS5yOwogICAgICAgICAgICB1LmwgPSAtIHUubDsKICAgICAgICAgICAgc3dhcCh1LmwsIHUucik7CiAgICAgICAgfQogICAgICAgIAogICAgICAgIAoJCXNvcnQoc2VnLmJlZ2luKCksIHNlZy5lbmQoKSwgW10oY29uc3QgU2VnJiBhLCBjb25zdCBTZWcmIGIpIHsKICAgICAgICAgICAgaWYgKGEubCAhPSBiLmwpIHJldHVybiBhLmwgPCBiLmw7CiAgICAgICAgICAgIHJldHVybiBhLnIgPiBiLnI7CiAgICAgICAgfSk7CiAgICAgICAgCiAgICAgICAgc2V0PGludD4gbDsKICAgICAgICBmb3IoYXV0byB1OiBzZWcpewogICAgICAgICAgICBhdXRvIGl0ID0gbC5sb3dlcl9ib3VuZCh1LnIpOwogICAgICAgICAgICBpZihpdCAhPSBsLmVuZCgpKSB7CiAgICAgICAgICAgICAgICBhbnNbdS5pbmRleF0gKz0gKml0IC0gdS5yOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGwuaW5zZXJ0KHUucik7CiAgICAgICAgfQoJCQoJCWZvcihpbnQgaSA9IDE7IGkgPCBzZWcuc2l6ZSgpOyBpKyspewoJCQlpZihzZWdbaV0ubCA9PSBzZWdbaS0xXS5sICYmIHNlZ1tpXS5yID09IHNlZ1tpLTFdLnIpewoJCQkJYW5zW3NlZ1tpXS5pbmRleF0gPSAwOwoJCQkJYW5zW3NlZ1tpLTFdLmluZGV4XSA9IDA7CgkJCX0KCQl9CgkJCiAgICAgICAgZm9yKGF1dG8gdTogYW5zKXsKICAgICAgICAgICAgY291dCA8PCB1IDw8IGVuZGw7CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIDA7Cn0=