from sys import stdin
data = stdin.readlines()

n = int(data[0])
a = [int(s) for s in data[1].split()]
q = int(data[2])

i = 1
l = []
while i <= q:
    l.append(int(data[i+2].split()[0]))
    l.append(int(data[i+2].split()[1]))
    i += 1

i = 0
while i <= q-1:
    m = 0
    while m <= n-1:
        if a[m] ==  l[2*i]:
            a[m] = l[2*i+1]
        m += 1
    print(sum(a))
    i += 1