#include <iostream>
#include <cassert>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <fstream>

using namespace std;

#define file cin

// hier implementiert fuer minimum
template< class T >
class order_statistic_tree {
	// protected:
public:
  T *_data;
  int _size;
  //static const int oo = 0x7fffffff;
public:
  order_statistic_tree() {
    _data = 0;
    _size = 0;
  }
  virtual ~order_statistic_tree() {
    delete[] _data;
  }

  virtual T op( T a, T b ) = 0;
  virtual T neutral_element() = 0;
  virtual int is_less( T a, T b ) = 0;

  void clear() {
    delete[] _data;
    _data = 0;
    _size = 0;
  }
	
  void resize( int size ) {
    int tmp = 1; // zweierpotenz
    while( tmp < size )
      tmp += tmp;
    size = tmp;

    if( _size == size )
      return;
    T *data = new T[ size*2 ];

    for( int i = 0; i < std::min( size, _size ); i++ )
      data[ size+i ] = _data[ _size+i ];
    for( int i = _size; i < size; i++ )
      data[ size+i ] = neutral_element();
    for( int i = size-1; i >= 1; i-- )
      data[i] = op( data[i+i], data[i+i+1] );
    delete[] _data;
    _data = data;
    _size = size;
  }

  T get_statistic( int l, int r ) { // inside of interval
    if( l >= r )
     return neutral_element();
    l += _size;
    r += _size;
    T res = _data[l];
    while( 1 ) {
      if( r-1 <= l )
        break;
      if( r & 1 )
        res = op( res, _data[r-1] );
      if( !( l & 1 ) )
        res = op( res, _data[l+1] );
      r /= 2;
      l /= 2;
    }
    return res;
  }
	
  T operator[]( int i ) const {
    return _data[ _size+i ];
  }
	
  void set_value( int i, T v ) {
    i += _size;
    _data[i] = v;
    while( i ) {
      _data[i>>1] = op( _data[i], _data[i^1] );
      i >>= 1;
    }
  }
};

template< class T >
class minimum_statistic : public order_statistic_tree< T > {
public:
  int is_less( T a, T b ) { return a < b; }
  T op( T a, T b ) { return std::min( a, b ); }
  T neutral_element() { return std::numeric_limits< T >::max(); }
	
  int find_index_of_minimum( int l, int r ) { // inside of interval
    if( l >= r )
      return 0;
    l += _size;
    r += _size;
    int mini = l;
    while( 1 ) {
      if( r-1 <= l )
        break;
      if( ( r & 1 ) && ( _data[r-1] < _data[mini] ) )
        mini = r-1;
      if( !( l & 1 ) && ( _data[l+1] < _data[mini] ) )
        mini = l+1;
      r /= 2;
      l /= 2;
    }
    while( mini < _size ) {
      mini += mini;
      if( _data[mini] > _data[mini+1] )
        mini++;
    }
    return mini - _size;
  }
};



typedef pair< string, int > PSI;

vector< PSI > in;
minimum_statistic< int > ost;

void solve( int a, int b ) {
	if( a >= b ) return;
	int split = ost.find_index_of_minimum( a, b );
	//	cout << split << " ";
	
	cout << "(";
	solve( a, split );
	cout << in[split].first << "/" << in[split].second;
	solve( split+1, b );
	cout << ")";
}

int main() {
	int n;
	//ifstream file( "heap.in" );
	while( cin >> n ) {
		if( n == 0 ) break;
		
		in.clear();
		for( int i = 0; i < n; i++ ) {
			string line;
			file >> line;
			int split = line.find( '/' );
			int v = atoi( line.substr( split+1 ).c_str() );
			string l = line.substr( 0, split );
			//			cout << l << " " << v << endl;
			
			in.push_back( PSI( l, v ) );
		}
		
		sort( in.begin(), in.end() );
		
		ost.resize( n );
		
		for( int i = 0; i < n; i++ )
			ost.set_value( i, -in[i].second );

		solve( 0, n );
		cout << endl;
	}
}
