
def count(A,B,C,s,q):
    if q == s:
        return 0
    else :
        for i,j in enumerate(A):
            if j == B[s]:
                A[i] = C[s]
        print(sum(A))
        return count(A,B,C,s+1,q)


n = int(input())
*A, = map(int, input().split())
q = int(input())
B = [0]*q
C = [0]*q
for i in range(q):
    B[i], C[i] = map(int, input().split())
count(A,B,C,0,q)