from collections import OrderedDict, Counter
dict = OrderedDict()
for _ in range(int(input())):
    name,_,price=raw_input().rpartition(' ')
    # ls = raw_input().split()
    dict[name] = dict.get(name,0) + int(price)

print('\n'.join(key+' '+str(value) for key,value in dict.items()))

"""
Sample Input

9
BANANA FRIES 12
POTATO CHIPS 30
APPLE JUICE 10
CANDY 5
APPLE JUICE 10
CANDY 5
CANDY 5
CANDY 5
POTATO CHIPS 30

Sample Output

BANANA FRIES 12
POTATO CHIPS 60
APPLE JUICE 20
CANDY 20

"""
c4a7fecb4105a9a240b1e0c2f4e4e1c33511fd99
<mask token>

<mask token>
for _ in range(int(input())):
    name, _, price = raw_input().rpartition(' ')
    dict[name] = dict.get(name, 0) + int(price)
print('\n'.join(key + ' ' + str(value) for key, value in dict.items()))
<mask token>

<mask token>
dict = OrderedDict()
for _ in range(int(input())):
    name, _, price = raw_input().rpartition(' ')
    dict[name] = dict.get(name, 0) + int(price)
print('\n'.join(key + ' ' + str(value) for key, value in dict.items()))
<mask token>

from collections import OrderedDict, Counter
dict = OrderedDict()
for _ in range(int(input())):
    name, _, price = raw_input().rpartition(' ')
    dict[name] = dict.get(name, 0) + int(price)
print('\n'.join(key + ' ' + str(value) for key, value in dict.items()))
<mask token>

from collections import OrderedDict, Counter
dict = OrderedDict()
for _ in range(int(input())):
    name,_,price=raw_input().rpartition(' ')
    # ls = raw_input().split()
    dict[name] = dict.get(name,0) + int(price)

print('\n'.join(key+' '+str(value) for key,value in dict.items()))

"""
Sample Input

9
BANANA FRIES 12
POTATO CHIPS 30
APPLE JUICE 10
CANDY 5
APPLE JUICE 10
CANDY 5
CANDY 5
CANDY 5
POTATO CHIPS 30

Sample Output

BANANA FRIES 12
POTATO CHIPS 60
APPLE JUICE 20
CANDY 20

"""