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]]

    idx = [x for x,v in enumerate(a) if v == b[i]]
    for x in idx:
        a[x] = c[i]
    ret += [str(sum(a))]

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