n = int(input())
a = list(map(int,input().split()))
q = int(input())
b,c = [0] * q,[0] * q
for i in range(q) :
    b[i],c[i] = map(int,input().split())
s = sum(a)
for i in range(q) :
    for j in range(n) :
        if a[j] == b[i] :
            a[j] = c[i]
            s += (c[i] - b[i])
    print(s)