from collections import Counter

N = int(eval(input()))

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

Q = int(eval(input()))

B = [list(map(int, input().split())) for _ in range(Q)]



res = sum(A)

A_counter = Counter(A)

for i, j in B:

    if i not in A_counter:

        A_counter[i] = 0

    if j not in A_counter:

        A_counter[j] = 0



    res += (j - i) * A_counter[i]

    print(res)

    

    A_counter[j] += A_counter[i]

    A_counter[i] = 0

from collections import Counter

N = int(eval(input()))

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

Q = int(eval(input()))

B = [list(map(int, input().split())) for _ in range(Q)]



res = sum(A)

A_counter = Counter(A)

for i, j in B:

    # if i not in A_counter:

    #     A_counter[i] = 0

    # if j not in A_counter:

    #     A_counter[j] = 0



    res += (j - i) * A_counter[i]

    print(res)



    A_counter[j] += A_counter[i]

    A_counter[i] = 0

from collections import Counter

N = int(eval(input()))
A = list(map(int, input().split()))
Q = int(eval(input()))
B = [list(map(int, input().split())) for _ in range(Q)]
res = sum(A)
A_counter = Counter(A)
for i, j in B:
    if i not in A_counter:
        A_counter[i] = 0
    if j not in A_counter:
        A_counter[j] = 0
    res += (j - i) * A_counter[i]
    print(res)
    A_counter[j] += A_counter[i]
    A_counter[i] = 0

from collections import Counter

N = int(eval(input()))
A = list(map(int, input().split()))
Q = int(eval(input()))
B = [list(map(int, input().split())) for _ in range(Q)]
res = sum(A)
A_counter = Counter(A)
for i, j in B:
    # if i not in A_counter:
    #     A_counter[i] = 0
    # if j not in A_counter:
    #     A_counter[j] = 0
    res += (j - i) * A_counter[i]
    print(res)
    A_counter[j] += A_counter[i]
    A_counter[i] = 0

-    if i not in A_counter: -        A_counter[i] = 0 -    if j not in A_counter: -        A_counter[j] = 0 +    # if i not in A_counter: +    #     A_counter[i] = 0 +    # if j not in A_counter: +    #     A_counter[j] = 0