n = int(input())
l = list(input().split())
q = int(input())

d = {}
for i in range(q):
    _l = list(input().split())
    l2 = [i for i, x in enumerate(l) if x == _l[0]]
    for e in l2:
        l[e] = _l[1]
    d[i] = sum(map(int, l))
    
for key in d.keys():
    print(d[key])