from operator import itemgetter

if __name__ == '__main__':
    n = int(input())
    input_list = [input() for i in range(n)]
    restaurant_list = []
    for index, _input in enumerate(input_list):
        _restaurant_data = {'id': index + 1, 'region': _input.split()[0], 'point': int(_input.split()[1])}
        restaurant_list.append(_restaurant_data)

    restaurant_list.sort(key=itemgetter('point'), reverse=True)
    restaurant_list.sort(key=itemgetter('region'))
    for restaurant in restaurant_list:
        print(restaurant['id'])
