import sys

from collections import Counter



read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

MOD = 1000000007





def main():

    N = int(readline())

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

    Q, *BC = list(map(int, read().split()))



    total = sum(A)

    d = Counter(A)

    for b, c in zip(BC[::2], BC[1::2]):

        total -= b * d[b]

        total += c * d[b]

        d[c] += d[b]

        d[b] = 0

        print(total)



    return





if __name__ == '__main__':

    main()

import sys

from collections import Counter



read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

MOD = 1000000007





def main():

    N = int(readline())

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

    Q, *BC = list(map(int, read().split()))



    total = sum(A)

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

    for a in A:

        d[a] += 1



    for b, c in zip(BC[::2], BC[1::2]):

        total += (c - b) * d[b]

        d[c] += d[b]

        d[b] = 0

        print(total)



    return





if __name__ == '__main__':

    main()

import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    Q, *BC = list(map(int, read().split()))
    total = sum(A)
    d = Counter(A)
    for b, c in zip(BC[::2], BC[1::2]):
        total -= b * d[b]
        total += c * d[b]
        d[c] += d[b]
        d[b] = 0
        print(total)
    return


if __name__ == "__main__":
    main()

import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    Q, *BC = list(map(int, read().split()))
    total = sum(A)
    d = [0] * (10**5 + 1)
    for a in A:
        d[a] += 1
    for b, c in zip(BC[::2], BC[1::2]):
        total += (c - b) * d[b]
        d[c] += d[b]
        d[b] = 0
        print(total)
    return


if __name__ == "__main__":
    main()

-    d = Counter(A) +    d = [0] * (10**5 + 1) +    for a in A: +        d[a] += 1 -        total -= b * d[b] -        total += c * d[b] +        total += (c - b) * d[b]