# 371 ms, 27032 KB

n = int(eval(input()))

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

q = int(eval(input()))

b = []

c = []

 

for _ in range(q):

    bi, ci = list(map(int, input().split()))

    b.append(bi)

    c.append(ci)

#bc = [map(int, input().split()) for _ in range(q)]

#b, c = [list(i) for i in zip(*bc)]

 

dic = {}

for aa in a:

    dic[aa] = dic.get(aa, 0) + 1

 

s = sum(a)

for i in range(q):

    if b[i] not in dic:

        print((str(s)))

        continue

    s += (c[i]-b[i]) * dic[b[i]]

    dic[c[i]] = dic.get(c[i], 0) + dic[b[i]]

    del dic[b[i]]

    print(s)
import sys

readline = sys.stdin.readline

 

 

def st(line):

    tmp = ''

    for l in line:

        if l == '\n':

            yield tmp

        elif l == ' ':

            yield tmp

            tmp = ''

        else:

            tmp += l

 

 

def solve():

    N = int(eval(input()))

    As = st(readline())

 

    d = dict()

    total = 0

    for a in As:

        a = int(a)

 

        if a in d:

            d[a] += 1

        else:

            d[a] = 1

        total += a

 

    Q = int(eval(input()))

    queries = (list(map(int, readline().strip().split())) for _ in range(Q))

 

    for que in queries:

        b, c = que

 

        if b not in d:

            print(total)

            continue

 

        n_b = d[b]

        d[b] = 0

 

        if c not in d:

            d[c] = 0

 

        d[c] += n_b

        total += (c - b) * n_b

 

        print(total)

 

 

def main():

    solve()

 

 

if __name__ == "__main__":

    main()
# 371 ms, 27032 KB
n = int(eval(input()))
a = list(map(int, input().split()))
q = int(eval(input()))
b = []
c = []
for _ in range(q):
    bi, ci = list(map(int, input().split()))
    b.append(bi)
    c.append(ci)
# bc = [map(int, input().split()) for _ in range(q)]
# b, c = [list(i) for i in zip(*bc)]
dic = {}
for aa in a:
    dic[aa] = dic.get(aa, 0) + 1
s = sum(a)
for i in range(q):
    if b[i] not in dic:
        print((str(s)))
        continue
    s += (c[i] - b[i]) * dic[b[i]]
    dic[c[i]] = dic.get(c[i], 0) + dic[b[i]]
    del dic[b[i]]
    print(s)

import sys

readline = sys.stdin.readline


def st(line):
    tmp = ""
    for l in line:
        if l == "\n":
            yield tmp
        elif l == " ":
            yield tmp
            tmp = ""
        else:
            tmp += l


def solve():
    N = int(eval(input()))
    As = st(readline())
    d = dict()
    total = 0
    for a in As:
        a = int(a)
        if a in d:
            d[a] += 1
        else:
            d[a] = 1
        total += a
    Q = int(eval(input()))
    queries = (list(map(int, readline().strip().split())) for _ in range(Q))
    for que in queries:
        b, c = que
        if b not in d:
            print(total)
            continue
        n_b = d[b]
        d[b] = 0
        if c not in d:
            d[c] = 0
        d[c] += n_b
        total += (c - b) * n_b
        print(total)


def main():
    solve()


if __name__ == "__main__":
    main()

-# 371 ms, 27032 KB -n = int(eval(input())) -a = list(map(int, input().split())) -q = int(eval(input())) -b = [] -c = [] -for _ in range(q): -    bi, ci = list(map(int, input().split())) -    b.append(bi) -    c.append(ci) -# bc = [map(int, input().split()) for _ in range(q)] -# b, c = [list(i) for i in zip(*bc)] -dic = {} -for aa in a: -    dic[aa] = dic.get(aa, 0) + 1 -s = sum(a) -for i in range(q): -    if b[i] not in dic: -        print((str(s))) -        continue -    s += (c[i] - b[i]) * dic[b[i]] -    dic[c[i]] = dic.get(c[i], 0) + dic[b[i]] -    del dic[b[i]] -    print(s) +import sys + +readline = sys.stdin.readline + + +def st(line): +    tmp = "" +    for l in line: +        if l == "\n": +            yield tmp +        elif l == " ": +            yield tmp +            tmp = "" +        else: +            tmp += l + + +def solve(): +    N = int(eval(input())) +    As = st(readline()) +    d = dict() +    total = 0 +    for a in As: +        a = int(a) +        if a in d: +            d[a] += 1 +        else: +            d[a] = 1 +        total += a +    Q = int(eval(input())) +    queries = (list(map(int, readline().strip().split())) for _ in range(Q)) +    for que in queries: +        b, c = que +        if b not in d: +            print(total) +            continue +        n_b = d[b] +        d[b] = 0 +        if c not in d: +            d[c] = 0 +        d[c] += n_b +        total += (c - b) * n_b +        print(total) + + +def main(): +    solve() + + +if __name__ == "__main__": +    main()