n = int(input().rstrip())

line = input().rstrip().split(' ')

a = []
for i in range(n):
    a.append(int(line[i]))

a.sort()

q = int(input().rstrip())

b = []
c = []

for i in range(q):
    line = input().rstrip().split(' ')
    b = int(line[0])
    c = int(line[1])

    for j in range(len(a)):
        if a[j] == b:
            a[j] = c

    ans = 0
    for j in range(len(a)):
        ans += a[j]

    print(ans)
