#include<bits/stdc++.h>
using namespace std;
#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back
const int N=2e6+10;
struct p{
int l, r,id;
p(int x,int y,int z){
l=x;
r=y;
id=z;
}
};
bool cmp(p x,p y){
return x.l<=y.l;
}
vector<p> v[N];
int a[N],b[N],c[N],m[N],ans[N];
void solve(){
int n;
cin>>n;
int res=0;
for(int i=1;i<=n;i++){
cin>>a[i]>>b[i]>>m[i];
v[a[i]+b[i]-m[i]].pb(p(a[i]-m[i],a[i],i));
}
for(int i=1;i<=n;i++){
int k=a[i]+b[i]-m[i];
vector<int> tem;
tem.clear();
sort(v[k].begin(),v[k].end(),cmp);
int dau,cuoi=-1;
for(int j=0;j<v[k].size();j++){
int t=max(0,v[k][j].l);
if(cuoi<t){
res++;
for(auto x:tem) ans[x]=a[x]-dau;
dau=t;
cuoi=v[k][j].r;
tem.clear();
tem.pb(v[k][j].id);
}
else{
dau=max(dau,t);
cuoi=min(cuoi,v[k][j].r);
tem.pb(v[k][j].id);
}
}
for(auto x:tem) ans[x]=a[x]-dau;
v[k].clear();
}
cout<<res<<'\n';
for(int i=1;i<=n;i++){
cout<<ans[i]<<' '<<m[i]-ans[i]<<'\n';
}
}
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int tt;
cin>>tt;
while(tt--){
solve();
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBpaSBwYWlyPGludCxpbnQ+CiNkZWZpbmUgZmkgZmlyc3QKI2RlZmluZSBzZSBzZWNvbmQKI2RlZmluZSBwYiBwdXNoX2JhY2sKY29uc3QgaW50IE49MmU2KzEwOwpzdHJ1Y3QgcHsKICAgIGludCBsLCByLGlkOwogICAgcChpbnQgeCxpbnQgeSxpbnQgeil7CiAgICAgICAgbD14OwogICAgICAgIHI9eTsKICAgICAgICBpZD16OwogICAgfQp9Owpib29sIGNtcChwIHgscCB5KXsKICAgIHJldHVybiB4Lmw8PXkubDsKfQp2ZWN0b3I8cD4gdltOXTsKaW50IGFbTl0sYltOXSxjW05dLG1bTl0sYW5zW05dOwp2b2lkIHNvbHZlKCl7CiAgICBpbnQgbjsKICAgIGNpbj4+bjsKICAgIGludCByZXM9MDsKICAgIGZvcihpbnQgaT0xO2k8PW47aSsrKXsKICAgICAgICBjaW4+PmFbaV0+PmJbaV0+Pm1baV07CiAgICAgICAgdlthW2ldK2JbaV0tbVtpXV0ucGIocChhW2ldLW1baV0sYVtpXSxpKSk7CiAgICB9CiAgICBmb3IoaW50IGk9MTtpPD1uO2krKyl7CiAgICAgICAgaW50IGs9YVtpXStiW2ldLW1baV07CiAgICAgICAgdmVjdG9yPGludD4gdGVtOwogICAgICAgIHRlbS5jbGVhcigpOwogICAgICAgIHNvcnQodltrXS5iZWdpbigpLHZba10uZW5kKCksY21wKTsKICAgICAgICBpbnQgZGF1LGN1b2k9LTE7CiAgICAgICAgZm9yKGludCBqPTA7ajx2W2tdLnNpemUoKTtqKyspewogICAgICAgICAgICBpbnQgdD1tYXgoMCx2W2tdW2pdLmwpOwogICAgICAgICAgICBpZihjdW9pPHQpewogICAgICAgICAgICAgICAgcmVzKys7CiAgICAgICAgICAgICAgICBmb3IoYXV0byB4OnRlbSkgYW5zW3hdPWFbeF0tZGF1OwogICAgICAgICAgICAgICAgZGF1PXQ7CiAgICAgICAgICAgICAgICBjdW9pPXZba11bal0ucjsKICAgICAgICAgICAgICAgIHRlbS5jbGVhcigpOwogICAgICAgICAgICAgICAgdGVtLnBiKHZba11bal0uaWQpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2V7CiAgICAgICAgICAgICAgICBkYXU9bWF4KGRhdSx0KTsKICAgICAgICAgICAgICAgIGN1b2k9bWluKGN1b2ksdltrXVtqXS5yKTsKICAgICAgICAgICAgICAgIHRlbS5wYih2W2tdW2pdLmlkKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBmb3IoYXV0byB4OnRlbSkgYW5zW3hdPWFbeF0tZGF1OwogICAgICAgIHZba10uY2xlYXIoKTsKICAgIH0KICAgIGNvdXQ8PHJlczw8J1xuJzsKICAgIGZvcihpbnQgaT0xO2k8PW47aSsrKXsKICAgICAgICBjb3V0PDxhbnNbaV08PCcgJzw8bVtpXS1hbnNbaV08PCdcbic7CiAgICB9ICAgIAoKfQppbnQzMl90IG1haW4oKXsKICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oMCk7CiAgICBjaW4udGllKDApO2NvdXQudGllKDApOwogICAgaW50IHR0OwogICAgY2luPj50dDsKICAgIHdoaWxlKHR0LS0pewogICAgICAgIHNvbHZlKCk7CiAgICB9Cn0=