import bisect
import collections
import copy
import heapq
import itertools
import math
import numpy
import string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


N = I()
A = LI()
Q = I()

for s in range(Q):
    BC = LI()
    for t in range(N):
        if A[t] == BC[0]:
            A[t] = BC[1]
    print(numpy.sum(A))
