n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = []
c = []
for i in range(q):
    _ = list(map(int, input().split()))
    c.append(_[1])
    b.append(_[0])

s = sum(a)

# 辞書型で度数を持つ
hist = {}
for i in range(n):
    if a[i] in hist:
        hist[a[i]] += 1
    else:
        hist[a[i]] = 1
# print(hist)

for i in range(q):
    diff = c[i] - b[i]
    if b[i] in hist:
        s += hist[b[i]]*diff
        print(s)
        if c[i] in hist:
            hist[c[i]] += hist[b[i]]
        else:
            hist[c[i]] = hist[b[i]]
            del hist[b[i]]
    else:
        print(s)
    # print(hist)
