import sys

input = sys.stdin.buffer.readline



n = int(eval(input()))

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

q = int(eval(input()))



from collections import Counter

C = Counter(A)

C = dict(C)

S = sum(A)

for i in range(q):

    b, c = list(map(int, input().split()))

    if b in C:

        vb = C[b]

        C[b] = 0

        S -= b*vb

        S += c*vb

        print(S)

        if c in C:

            C[c] += vb

        else:

            C[c] = vb

    else:

        print(S)

import sys

input = sys.stdin.buffer.readline



n = int(eval(input()))

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

S = sum(A)



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

for a in A:

    D[a] += 1



q = int(eval(input()))

for i in range(q):

    b, c = list(map(int, input().split()))

    S -= D[b]*b

    S += D[b]*c

    D[c] += D[b]

    D[b] = 0

    print(S)

import sys

input = sys.stdin.buffer.readline
n = int(eval(input()))
A = list(map(int, input().split()))
q = int(eval(input()))
from collections import Counter

C = Counter(A)
C = dict(C)
S = sum(A)
for i in range(q):
    b, c = list(map(int, input().split()))
    if b in C:
        vb = C[b]
        C[b] = 0
        S -= b * vb
        S += c * vb
        print(S)
        if c in C:
            C[c] += vb
        else:
            C[c] = vb
    else:
        print(S)

import sys

input = sys.stdin.buffer.readline
n = int(eval(input()))
A = list(map(int, input().split()))
S = sum(A)
D = [0] * (10**5 + 1)
for a in A:
    D[a] += 1
q = int(eval(input()))
for i in range(q):
    b, c = list(map(int, input().split()))
    S -= D[b] * b
    S += D[b] * c
    D[c] += D[b]
    D[b] = 0
    print(S)

+S = sum(A) +D = [0] * (10**5 + 1) +for a in A: +    D[a] += 1 -from collections import Counter - -C = Counter(A) -C = dict(C) -S = sum(A) -    if b in C: -        vb = C[b] -        C[b] = 0 -        S -= b * vb -        S += c * vb -        print(S) -        if c in C: -            C[c] += vb -        else: -            C[c] = vb -    else: -        print(S) +    S -= D[b] * b +    S += D[b] * c +    D[c] += D[b] +    D[b] = 0 +    print(S)