#!/usr/bin/env pypy
 
import sys
import string
def get_int(): return int(sys.stdin.readline().strip())
def get_ints(): return map(int, sys.stdin.readline().strip().split()) 
def get_list(): return list(map(int, sys.stdin.readline().strip().split())) 
def get_string(): return sys.stdin.readline().strip()
def out(data): return sys.stdout.write(str(data))
def out_list(arr): return sys.stdout.write(' '.join(str(e) for e in arr))

MAX = 10**9
MOD = 10**9 + 7

n = get_int()
arr = get_list()
q = get_int()
sum_ = sum(arr)

for _ in range(q):
	a, b = get_ints()
	if a in arr:
		sum_ += arr.count(a) * (b - a)
		arr = [b if x == a else x for x in arr]
	out(sum_)
	out('\n')


