n = int(input())
a = list(map(int, input().split()))
q = int(input())

s = sum(a)

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