Buggy python submission (verdict: Time Limit Exceeded):
nb=int(input())
liste = [int(x) for x in input().split()]
liste2= [0]*((10**5)+1)
for loop in range(len(liste)):
  liste2[liste[loop]] +=1
nba = int(input())
somme = sum(liste)
for loop in range(nba):
  n,r = map(int,input().split())
  roger = liste2[n]
  for loop in range(len(liste)):
    if liste[loop]==n:
      liste[loop] = r
  diff = r-n
  somme += diff * roger
  liste2[r] += liste2[n]
  liste2[n] = 0
  print(somme)

Fixed submission:
nb=int(input())
liste = [int(x) for x in input().split()]
liste2= [0]*((10**5)+1)
for loop in range(len(liste)):
  liste2[liste[loop]] +=1
nba = int(input())
somme = sum(liste)
for loop in range(nba):
  n,r = map(int,input().split())
  roger = liste2[n]
  diff = r-n
  somme += diff * roger
  liste2[r] += liste2[n]
  liste2[n] = 0
  print(somme)

Buggy python submission (verdict: Runtime Error):
nb=int(input())
liste = [int(x) for x in input().split()]
liste2= [0]*(10**5)
for loop in range(len(liste)):
  liste2[liste[loop]] = liste.count(liste[loop])
nba = int(input())
somme = sum(liste)
for loop in range(nba):
  n,r = map(int,input().split())
  roger = liste2[n]
  for loop in range(len(liste)):
    if liste[loop]==n:
      liste[loop] = r
  diff = r-n
  somme += diff * roger
  liste2[r] += liste2[n]
  liste2[n] = 0
  print(somme)


Fixed submission:
nb=int(input())
liste = [int(x) for x in input().split()]
liste2= [0]*((10**5)+1)
for loop in range(len(liste)):
  liste2[liste[loop]] +=1
nba = int(input())
somme = sum(liste)
for loop in range(nba):
  n,r = map(int,input().split())
  roger = liste2[n]
  diff = r-n
  somme += diff * roger
  liste2[r] += liste2[n]
  liste2[n] = 0
  print(somme)

Buggy python submission (verdict: Time Limit Exceeded):
nb=int(input())
liste = [int(x) for x in input().split()]
nba = int(input())
somme = sum(liste)
for loop in range(nba):
  n,r = map(int,input().split())
  roger = liste.count(n)
  for loop in range(roger):
    liste.append(r)
  diff = r-n
  somme += diff * roger
  print(somme)

Fixed submission:
nb=int(input())
liste = [int(x) for x in input().split()]
liste2= [0]*((10**5)+1)
for loop in range(len(liste)):
  liste2[liste[loop]] +=1
nba = int(input())
somme = sum(liste)
for loop in range(nba):
  n,r = map(int,input().split())
  roger = liste2[n]
  diff = r-n
  somme += diff * roger
  liste2[r] += liste2[n]
  liste2[n] = 0
  print(somme)

Buggy python submission (verdict: Time Limit Exceeded):
nb=int(input())
liste = [int(x) for x in input().split()]
nba = int(input())
for loop in range(nba):
  n,r = map(int,input().split())
  for loop in range(len(liste)):
    if liste[loop]==n:
      liste[loop] = r
  print(sum(liste))


Fixed submission:
nb=int(input())
liste = [int(x) for x in input().split()]
liste2= [0]*((10**5)+1)
for loop in range(len(liste)):
  liste2[liste[loop]] +=1
nba = int(input())
somme = sum(liste)
for loop in range(nba):
  n,r = map(int,input().split())
  roger = liste2[n]
  diff = r-n
  somme += diff * roger
  liste2[r] += liste2[n]
  liste2[n] = 0
  print(somme)

Buggy python submission (verdict: Time Limit Exceeded):
nb=int(input())
liste = [int(x) for x in input().split()]
nba = int(input())
for loop in range(nba):
  n,r = map(int,input().split())
  for loop in range(len(liste)):
    if liste[loop]==n:
      liste[loop] = r
  print(sum(liste))


Fixed submission:
nb=int(input())
liste = [int(x) for x in input().split()]
liste2= [0]*((10**5)+1)
for loop in range(len(liste)):
  liste2[liste[loop]] +=1
nba = int(input())
somme = sum(liste)
for loop in range(nba):
  n,r = map(int,input().split())
  roger = liste2[n]
  diff = r-n
  somme += diff * roger
  liste2[r] += liste2[n]
  liste2[n] = 0
  print(somme)