N = int(input())
A = list(map(str, input().split()))
Q = int(input())
B = [0]*Q
C = [0]*Q
s = sum(list(map(int,A)))
for i in range(Q):
    B[i], C[i] = map(str, input().split())

for i in range(Q):
    if B[i] in A:        
        string = ",".join(A)
        string_new = string.replace(B[i],C[i])
        A =  string_new.split(",")
        s = sum(list(map(int,A)))
    
    print(s)