# -*- coding: utf-8 -*-
"""
Created on Tue Jun 23 21:04:33 2020

@author: naoki
"""

N = int(input()) # input the row A length "N" 
A = list(map(int,input().split())) # input the row of A 
Q = int(input()) # input the number of trying operation 
BC = [list(map(int,input().split())) for i in range(Q)]

for i in range(Q):
    S = 0 # Sum of all conponents of the row "A"
    for j in range(N):
        if A[j] == BC[i][0]:
            A[j] = BC[i][1]
        S +=A[j]
    print(S)

