import numpy as np
import sys
from bisect import bisect_right, bisect_left

readline = sys.stdin.readline

# 入力にかかる最大計算量O(NlogN)：クイックソート
N = int(input())
A = np.array(readline().split(), np.int64)
# A_sort = np.sort(A)
A_sum = sum(A)
Q = int(input())
BC = np.array([np.array(readline().split(), np.int64) for n in range(Q)], np.int64)
# BC[N][0,1]

# ここの計算量O(N(logN + logN))
for q in range(Q):
    # A = [BC[q][1] if x==BC[q][0] else x for x in A]
    # A[bisect.bisect_left(A, BC[q][0]):bisect.bisect_right(A, BC[q][0])] = BC[q][1]
    '''
    plus_num = BC[q][1] - BC[q][0]
    left = bisect_left(A_sort, BC[q][0])
    right = bisect_right(A_sort, BC[q][0])
    plus_multiple = right - left
    A_sort[left:right] = BC[q][1]
    A_sort = np.sort(A_sort)
    '''
    plus_num = BC[q][1] - BC[q][0]
    plus_multiple = np.count_nonzero(A == BC[q][0])
    A[A==BC[q][0]] = BC[q][1]

    A_sum = A_sum + plus_num*plus_multiple
    print(A_sum)

