import sys

INF = 1 << 60

MOD = 10**9 + 7 # 998244353

sys.setrecursionlimit(2147483647)

input = lambda:sys.stdin.readline().rstrip()

from collections import Counter

def resolve():

    n = int(eval(input()))

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

    total = 0

    for key, val in list(C.items()):

        total += key * val



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

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

        k = C[b]

        total += k * (c - b)

        C[b] = 0

        C[c] += k

        print(total)

resolve()
import sys

INF = 1 << 60

MOD = 10**9 + 7 # 998244353

sys.setrecursionlimit(2147483647)

input = lambda:sys.stdin.readline().rstrip()

from collections import Counter

def resolve():

    n = int(eval(input()))

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

    total = 0

    for key, val in list(C.items()):

        total += key * val



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

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

        num = C[b]

        total += (c - b) * num

        C[b] = 0

        C[c] += num

        print(total)

resolve()
import sys

INF = 1 << 60
MOD = 10**9 + 7  # 998244353
sys.setrecursionlimit(2147483647)
input = lambda: sys.stdin.readline().rstrip()
from collections import Counter


def resolve():
    n = int(eval(input()))
    C = Counter(list(map(int, input().split())))
    total = 0
    for key, val in list(C.items()):
        total += key * val
    for _ in range(int(eval(input()))):
        b, c = list(map(int, input().split()))
        k = C[b]
        total += k * (c - b)
        C[b] = 0
        C[c] += k
        print(total)


resolve()

import sys

INF = 1 << 60
MOD = 10**9 + 7  # 998244353
sys.setrecursionlimit(2147483647)
input = lambda: sys.stdin.readline().rstrip()
from collections import Counter


def resolve():
    n = int(eval(input()))
    C = Counter(list(map(int, input().split())))
    total = 0
    for key, val in list(C.items()):
        total += key * val
    for _ in range(int(eval(input()))):
        b, c = list(map(int, input().split()))
        num = C[b]
        total += (c - b) * num
        C[b] = 0
        C[c] += num
        print(total)


resolve()

-        k = C[b] -        total += k * (c - b) +        num = C[b] +        total += (c - b) * num -        C[c] += k +        C[c] += num