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