n = int(input())
a = list(map(int,input().split()))
q = int(input())

b = []
c = []
ret = []

for i in range(q):
    inp = list(map(int,input().split()))
    b += [inp[0]]
    c += [inp[1]]

    ll = set(a)
    if b[i] in ll:
        cnt = a.count(b[i])
        for x in range(cnt):
            idx = a.index(b[i])
            a[idx] = c[i]
    ret += [str(sum(a))]

print('\n'.join(ret))