N = int(input())
A = list(map(str, input().split()))
Q = int(input())
S = []
c = 0

for i in range(Q):
    B, C = map(str,input().split())
    if B in A:
        c = A.count(B)
        string = ",".join(A)
        string_new = string.replace(B, C,c)
        A =  string_new.split(",")

    S.append(sum(map((lambda x: int(x)), A)))


for s in S:
    print(s)