#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>


struct node {
        char * str;
        int prio;
        int ord;
        int left, right, parent;
};

struct node nodes[50100];
int N;
char buf[10000];

int comps (const void *s11, const void *s22)
{
	node *s1 = (node*)s11;
	node *s2 = (node*)s22;
        return strcmp (s1->str, s2->str);
}

int compp (const void *s11, const void *s22)
{
	node *s1 = (node*)s11;
	node *s2 = (node*)s22;
        if (s1->prio < s2->prio)
                return -1;

        if (s1->prio > s2->prio)
                return 1;
        return 0;
}

int root;

void insert2 (int i)
{
        int pivot = i-1;
        while (nodes[i].prio > nodes[pivot].prio) {
                if (nodes[pivot].parent < 0) {
                        root = i;
                        nodes[i].left = pivot;
                        nodes[pivot].parent = i;
                        return;
                } else {
                        pivot = nodes[pivot].parent;
                }
        }
        nodes[i].left = nodes[pivot].right;
        nodes[nodes[pivot].right].parent = i;
        nodes[pivot].right = i;
        nodes[i].parent = pivot;
}

void insert (int i)
{
        int root = 0;
        while (1) {
                if (nodes[i].ord < nodes[root].ord) {
                        if (nodes[root].left >= 0)
                                root = nodes[root].left;
                        else {
                                nodes[root].left = i;
                                nodes[i].parent = root;
                                return;
                        }
                } else {
                        if (nodes[root].right >= 0)
                                root = nodes[root].right;
                        else {
                                nodes[root].right = i;
                                nodes[i].parent = root;
                                return;
                        }
                }
        }
        
}

void print (int i)
{
        if (i < 0)
                return;
        printf ("(");
        print (nodes[i].left);
        printf ("%s/%d", nodes[i].str, nodes[i].prio);
        print (nodes[i].right);
        printf (")");
}
#ifndef DEBUG
//extern char * strdup (char *);
#endif
int main ()
{
        FILE * in = stdin;
        int i;
        assert (in);
        while (1) {
                fscanf (in, "%d", &N);
                if (!N)
                        break;
                for (i=0; i<N; ++i) {
                        char * tmp;
                        fscanf (in, "%s", buf);
                        tmp = strchr (buf, '/');
                        *tmp++ = 0;
                        sscanf (tmp, "%d", &nodes[i].prio);
                        nodes[i].str = strdup (buf);
                        nodes[i].left = nodes[i].right = nodes[i].parent = -1;
                }
                qsort (nodes, N, sizeof (struct node), comps);
                for (i=0; i<N; ++i)
                        nodes[i].ord = i;
                /*qsort (nodes, N, sizeof (struct node), compp); */
                root = 0;
                for (i=1; i<N; ++i) {
                        insert2 (i);
                }
                print (root);
                printf ("\n");
                for (i=0; i<N; ++i)
                        free (nodes[i].str);
        } 
        return 0;
}
