N = int(eval(input()))

A = list(map(int,input().split()))

Q = int(eval(input()))

import numpy as np



num_count = [0]*(10**5+1)

num_count = np.array(num_count)

tmp = np.arange(10**5+1)

tmp_sum = sum(A)

for i in A:

    num_count[i] += 1



for q in range(Q):

    B,C = list(map(int,input().split()))

    tmp_C = C*(num_count[B])

    tmp_B = B*(num_count[B])

    num_count[C] += num_count[B]

    num_count[B] = 0

    tmp_sum = tmp_sum + tmp_C - tmp_B

    print(tmp_sum)
N = int(eval(input()))

A = list(map(int,input().split()))



num_count = [0]*(10**5+1)

tmp_sum = sum(A)

for i in A:

    num_count[i] += 1



for q in range(int(eval(input()))):

    B,C = list(map(int,input().split()))

    gain = C*(num_count[B])

    loss = B*(num_count[B])

    num_count[C] += num_count[B]

    num_count[B] = 0

    tmp_sum = tmp_sum + gain - loss

    print(tmp_sum)

N = int(eval(input()))
A = list(map(int, input().split()))
Q = int(eval(input()))
import numpy as np

num_count = [0] * (10**5 + 1)
num_count = np.array(num_count)
tmp = np.arange(10**5 + 1)
tmp_sum = sum(A)
for i in A:
    num_count[i] += 1
for q in range(Q):
    B, C = list(map(int, input().split()))
    tmp_C = C * (num_count[B])
    tmp_B = B * (num_count[B])
    num_count[C] += num_count[B]
    num_count[B] = 0
    tmp_sum = tmp_sum + tmp_C - tmp_B
    print(tmp_sum)

N = int(eval(input()))
A = list(map(int, input().split()))
num_count = [0] * (10**5 + 1)
tmp_sum = sum(A)
for i in A:
    num_count[i] += 1
for q in range(int(eval(input()))):
    B, C = list(map(int, input().split()))
    gain = C * (num_count[B])
    loss = B * (num_count[B])
    num_count[C] += num_count[B]
    num_count[B] = 0
    tmp_sum = tmp_sum + gain - loss
    print(tmp_sum)

-Q = int(eval(input())) -import numpy as np - -num_count = np.array(num_count) -tmp = np.arange(10**5 + 1) -for q in range(Q): +for q in range(int(eval(input()))): -    tmp_C = C * (num_count[B]) -    tmp_B = B * (num_count[B]) +    gain = C * (num_count[B]) +    loss = B * (num_count[B]) -    tmp_sum = tmp_sum + tmp_C - tmp_B +    tmp_sum = tmp_sum + gain - loss