N = int(input())
A = input().split()
A = [int(s) for s in A]

num = int(input())
for i in range(num):
    B, C = map(int, input().split())
    indexes = [i for i, x in enumerate(A) if x == B]
    for j in range(len(indexes)):
        A[indexes[j]] = C
    sum = 0
    for i in range(N):
        sum += A[i]
    print(sum)
