# 371 ms, 27032 KB

n = int(eval(input()))

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

q = int(eval(input()))

b = []

c = []

 

bc = [list(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)
# 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)
# 371 ms, 27032 KB
n = int(eval(input()))
a = list(map(int, input().split()))
q = int(eval(input()))
b = []
c = []
bc = [list(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)

# 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)

-bc = [list(map(int, input().split())) for _ in range(q)] -b, c = [list(i) for i in zip(*bc)] +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)]