import collections
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
c = collections.Counter(A)
counter_key = list(c.keys())
counter_value = list(c.values())
list_sum_A=[]
sum_A=sum(A)
list_sum_A.append(sum_A)
B_list = []
C_list = []
for i in range(Q):
    B,C= map(int,input().split())
    B_list.append(B)
    C_list.append(C)

for i in range(1,Q+1):
    B = B_list[i-1]
    C = C_list[i-1]
    if(B not in counter_key):
        list_sum_A.append(list_sum_A[i-1])
    else:
        key_index=counter_key.index(B)
        list_sum_A.append(list_sum_A[i-1]+C*counter_value[key_index]-B*counter_value[key_index])
        if(C not in counter_key):
            counter_key[key_index]=C
        else:
            C_value_index = counter_key.index(C)
            counter_value[C_value_index]=counter_value[C_value_index]+counter_value[key_index]
            counter_value.pop(key_index)
            counter_key.pop(key_index)
for i in range(1,Q+1):
    print(list_sum_A[i])