#include <stdio.h>
#include <math.h>
typedef struct{
int start;
int end;
} Interval;
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define MAXN 10
void printInterval(Interval one);
_Bool isOverlap(Interval first, Interval second);
int main()
{
_Bool checked[10] = {0};
Interval Itvl[10];
int N;
scanf("%d\n", &N);
for (int i=0;i<N;i++) {
scanf("%d %d\n", &Itvl[i].start, &Itvl[i].end);
}
for (int i=0; i<N; i++) {
for (int j=i+1; j<N; j++) {
if (Itvl[i].start>Itvl[j].start) {
Interval temp;
temp = Itvl[i];
Itvl[i] = Itvl[j];
Itvl[j] = temp;
}
}
}
for (int i=0; i<N; i++) {
if (!checked[i]) {
printInterval(Itvl[i]);
for (int j=i+1; j<N; j++) {
if (isOverlap(Itvl[i], Itvl[j])) {
printInterval(Itvl[j]);
checked[j] = 1;
}
}
printf("\n");
}
}
return 0;
}
void printInterval(Interval one) {
printf("[%d,%d] ", one.start, one.end);
}
_Bool isOverlap(Interval first, Interval second) {
_Bool bRet = 0;
if (max(first.start, second.start) <= min(first.end, second.end)) {
bRet = 1;
} else {
bRet = 0;
}
return bRet;
}