#include<bits/stdc++.h>
using namespace std;
struct Node{
    int h,e;
    bool operator <(const Node &a)const{return h<a.h;}
};
int n,b,h,e,H,E,c,x;
priority_queue<Node>Q;
int main(){
    cin>>n>>b>>h>>e;
    printf("(%d,%d)",b,h);H=h;E=e;
    for(int i=2;i<=n;i++){
        cin>>b>>h>>e;
        if(b>E){
            while(!Q.empty()){
                if(Q.top().e<=E)Q.pop();
                else {printf("(%d,%d)",E,Q.top().h);H=Q.top().h;E=Q.top().e;}
            }
        }
        if(b>E){printf("(%d,0)",E);H=0;E=b;}
        if(h==H){if(e>E)E=e;}
        else if(h<H){if(e>E)Q.push((Node){h,e});}
        else {printf("(%d,%d)",b,h);if(E>e)Q.push((Node){H,E});H=h;E=e;}
    }
    printf("(%d,0)",E);
    return 0;
}

/**************************************************************
	Problem: 1756
	User: admin
	Language: C++
	Result: Accepted
	Time:6 ms
	Memory:2076 kb
****************************************************************/