N = int(input())
A = list(map(str, input().split()))
Q = int(input())
S = []
s = sum(map((lambda x: int(x)), A))


for i in range(Q):
    B, C = map(str,input().split())
    if B in A:
        string = ",".join(A)
        string_new = string.replace(B,C)
        A =  string_new.split(",")
        s = sum(map((lambda x: int(x)), A))
        S.append(s)


    else:
        S.append(s)



for s in S:
    print(s)
