# -*- 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)]
S = 0 
for i in A:
    S += i# Sum of all conponents of the row "A"
for B,C in BC:
    count = 0 # renewing count 
    count = A.count(B) # counting the number of "B"
    A = [C if i == B else i for i in A]   # changing B to C  
    S = S + (C - B) * count 
    print(S)

