n = int(eval(input()))

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

b = {}

for x in a:

  try:

    if b[x] != -1:

      b[x] += 1

  except:

    b[x] = 1

q = int(eval(input()))

ans = sum(a)

for _ in range(q):

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

  try:

    if b[x] != -1:

      bx = b[x]

      b[x] = 0

  except:

    print(ans)

    continue

  try:

    if b[y] != -1:

      b[y] += bx

  except:

    b[y] = bx

  ans += bx * (y-x)

  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)
n = int(eval(input()))
a = list(map(int, input().split()))
b = {}
for x in a:
    try:
        if b[x] != -1:
            b[x] += 1
    except:
        b[x] = 1
q = int(eval(input()))
ans = sum(a)
for _ in range(q):
    x, y = list(map(int, input().split()))
    try:
        if b[x] != -1:
            bx = b[x]
            b[x] = 0
    except:
        print(ans)
        continue
    try:
        if b[y] != -1:
            b[y] += bx
    except:
        b[y] = bx
    ans += bx * (y - x)
    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)

-b = {} +b = [0 for _ in range(100001)] -    try: -        if b[x] != -1: -            b[x] += 1 -    except: -        b[x] = 1 +    b[x] += 1 +ans = sum(a) -ans = sum(a) -    try: -        if b[x] != -1: -            bx = b[x] -            b[x] = 0 -    except: -        print(ans) -        continue -    try: -        if b[y] != -1: -            b[y] += bx -    except: -        b[y] = bx -    ans += bx * (y - x) +    ans += (y - x) * b[x] +    b[x], b[y] = 0, b[x] + b[y]