# -*- 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
num = [0 for i in range(100001)] 
for i in A:
    S += i # Sum of all conponents of the row "A"
    num[i]+=1 

for B,C in BC:
    S = S + (C - B) * num[B+1]
    num[C+1] += num[B+1]
    num[B+1] = 0 
    print(S)

