# -*- coding: utf-8 -*-
"""
Created on Mon Sep  7 01:00:02 2020

@author: liang
"""
N = int(input())
A = [int(i) for i in input().split()]
Q = int(input())

d = dict()
for i in A:
    if i in d.keys():
        d[i] += 1
    else:
        d[i] = 1

ans = sum(A)

for i in range(Q):
    b, c = map(int, input().split())
    if b in d.keys():
        ans += (c-b)*d[b]
        if c in d.keys():
            d[c] += d[b]
        else:
            d[c] = d[b]
    print(ans)