n = int(eval(input()))

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

b = [0 for _ in range(100001)]

for x in a:

  b[x] += 1

ans = sum(a)

q = int(eval(input()))

for _ in range(q):

  x,y = list(map(int,input().split()))

  ans += (y-x) * b[x]

  b[x],b[y] = 0,b[x]+b[y]

  print(ans)
#15:30

n = int(eval(input()))

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

b = {}

for x in a:

  b[x] = 0

q = int(eval(input()))

inp = []

for _ in range(q):

  x,y = list(map(int,input().split()))

  b[x] = 0

  b[y] = 0

  inp.append([x,y])

for x in a:

  b[x] += 1

ans = sum(a)

for z in inp:

  x,y = z

  ans += (y-x) * b[x]

  b[x],b[y] = 0,b[x]+b[y]

  print(ans)
n = int(eval(input()))
a = list(map(int, input().split()))
b = [0 for _ in range(100001)]
for x in a:
    b[x] += 1
ans = sum(a)
q = int(eval(input()))
for _ in range(q):
    x, y = list(map(int, input().split()))
    ans += (y - x) * b[x]
    b[x], b[y] = 0, b[x] + b[y]
    print(ans)

# 15:30
n = int(eval(input()))
a = list(map(int, input().split()))
b = {}
for x in a:
    b[x] = 0
q = int(eval(input()))
inp = []
for _ in range(q):
    x, y = list(map(int, input().split()))
    b[x] = 0
    b[y] = 0
    inp.append([x, y])
for x in a:
    b[x] += 1
ans = sum(a)
for z in inp:
    x, y = z
    ans += (y - x) * b[x]
    b[x], b[y] = 0, b[x] + b[y]
    print(ans)

+# 15:30 -b = [0 for _ in range(100001)] +b = {} +for x in a: +    b[x] = 0 +q = int(eval(input())) +inp = [] +for _ in range(q): +    x, y = list(map(int, input().split())) +    b[x] = 0 +    b[y] = 0 +    inp.append([x, y]) -q = int(eval(input())) -for _ in range(q): -    x, y = list(map(int, input().split())) +for z in inp: +    x, y = z