
# https://www.hackerrank.com/challenges/py-collections-ordereddict/problem?h_r=profile


from collections import OrderedDict


def seperate_product_names(product):

    product_name = ""
    price = 0
 

    for element in product:
        
        if element.isdigit():
                price = int(element)
        else :
            product_name += element + " "
    
    return product_name, price


def print_all(ordered_dict):

    for key, value in ordered_dict.items():
        print(f"{key} {value}")


if __name__ == '__main__':
    
    N = int(input())
    ordered_dict = OrderedDict()

    while N > 0:
        
        product = input().split()
        product_name, price = seperate_product_names(product)

        if product_name in ordered_dict.keys():
            ordered_dict[product_name] = ordered_dict[product_name] + int(price)
        else: 
            ordered_dict[product_name] = int(price)

        N -= 1


    

    
   

    



# https://www.hackerrank.com/challenges/py-collections-ordereddict/problem?h_r=profile


from collections import OrderedDict


def seperate_product_names(product):

    product_name = ""
    price = 0
 

    for element in product:
        
        if element.isdigit():
                price = int(element)
        else :
            product_name += element + " "
    
    return product_name, price


def print_all(ordered_dict):

    for key, value in ordered_dict.items():
        print(f"{key} {value}")


if __name__ == '__main__':
    
    N = int(input())
    ordered_dict = OrderedDict()

    while N > 0:
        
        product = input().split()
        product_name, price = seperate_product_names(product)

        if product_name in ordered_dict.keys():
            ordered_dict[product_name] = ordered_dict[product_name] + int(price)
        else: 
            ordered_dict[product_name] = int(price)

        N -= 1


    

    
   

    


# https://www.hackerrank.com/challenges/py-collections-ordereddict/problem?h_r=profile