n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = []
c = []
ans = sum(a)
for i in range(q):
    bi,ci = map(int, input().split())
    b.append(bi)
    c.append(ci)
for i in range(q):
    ans += a.count(b[i]) * (c[i]-b[i])
    for j in range(a.count(b[i])):
        a.append(c[i])
    a = [j for j in a if j != b[i]]
    print(ans)