import bisect,collections,copy,heapq,itertools,math,numpy,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()
sum = 0

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