Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N=int(input())
A=list(map(int,(input().split())))
npArray = np.array(A)
npArray=npArray.copy()
ans=np.sum(npArray)
Q=int(input())

for i in range(Q):
  L, R = map(int,(input().split()))
  B_count=np.count_nonzero(npArray == L)
  sa=(R-L)*B_count
  #npArray = np.where(npArray == L,R, npArray)
  npArray[npArray == L] = R
  ans= ans+sa
  print(ans)



Fixed submission:
import collections
import copy
N=int(input())
A=list(map(int,(input().split())))
ans=sum(A)
Q=int(input())
col = collections.Counter(A)

for i in range(Q):
  L, R = map(int,(input().split()))
  sa=(R-L)*col[L]
  col[R]+=copy.copy(col[L])
  col[L]=0
  ans= ans+sa
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N=int(input())
A=list(map(int,(input().split())))
npArray = np.array(A)
npArray=npArray.copy()
ans=np.sum(npArray)
Q=int(input())

for i in range(Q):
  L, R = map(int,(input().split()))
  B_count=np.count_nonzero(npArray == L)
  sa=(R-L)*B_count
  npArray = np.where(npArray == L,R, npArray)
  ans= ans+sa
  print(ans)

Fixed submission:
import collections
import copy
N=int(input())
A=list(map(int,(input().split())))
ans=sum(A)
Q=int(input())
col = collections.Counter(A)

for i in range(Q):
  L, R = map(int,(input().split()))
  sa=(R-L)*col[L]
  col[R]+=copy.copy(col[L])
  col[L]=0
  ans= ans+sa
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N=int(input())
A=list(map(int,(input().split())))
npArray = np.array(A)
npArray=npArray.copy()
ans=np.sum(npArray)
Q=int(input())
B=[]
C=[]
for _ in range(Q):
  L, R = map(int,(input().split()))
  B.append(L)
  C.append(R)

for i in range(Q):
  B_count=np.count_nonzero(npArray == B[i])
  sa=(C[i]-B[i])*B_count
  upNpArray = np.where(npArray == B[i], C[i], npArray)
  ans= ans+sa
  print(ans)
  npArray=upNpArray.copy()


Fixed submission:
import collections
import copy
N=int(input())
A=list(map(int,(input().split())))
ans=sum(A)
Q=int(input())
col = collections.Counter(A)

for i in range(Q):
  L, R = map(int,(input().split()))
  sa=(R-L)*col[L]
  col[R]+=copy.copy(col[L])
  col[L]=0
  ans= ans+sa
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N=int(input())
A=list(map(int,(input().split())))
npArray = np.array(A)
npArray=npArray.copy()
Q=int(input())
B=[]
C=[]
ans=0
for _ in range(Q):
  L, R = map(int,(input().split()))
  B.append(L)
  C.append(R)

for i in range(Q):
  upNpArray = np.where(npArray == B[i], C[i], npArray)
  print(np.sum(upNpArray))
  npArray=upNpArray.copy()

Fixed submission:
import collections
import copy
N=int(input())
A=list(map(int,(input().split())))
ans=sum(A)
Q=int(input())
col = collections.Counter(A)

for i in range(Q):
  L, R = map(int,(input().split()))
  sa=(R-L)*col[L]
  col[R]+=copy.copy(col[L])
  col[L]=0
  ans= ans+sa
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(str,(input().split())))
Q=int(input())
B=[]
C=[]
for _ in range(Q):
  L, R = map(str,(input().split()))
  B.append(L)
  C.append(R)

for i in range(Q):
  A_string = ",".join(A)
  A_new = A_string.replace(B[i],C[i])
  A =  A_new.split(",")
  int_A =map((lambda x: int(x)), A)
  print(sum(int_A))

Fixed submission:
import collections
import copy
N=int(input())
A=list(map(int,(input().split())))
ans=sum(A)
Q=int(input())
col = collections.Counter(A)

for i in range(Q):
  L, R = map(int,(input().split()))
  sa=(R-L)*col[L]
  col[R]+=copy.copy(col[L])
  col[L]=0
  ans= ans+sa
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(str,(input().split())))
Q=int(input())
B=[]
C=[]
for _ in range(Q):
  L, R = map(str,(input().split()))
  B.append(L)
  C.append(R)

for i in range(Q):
  A_string = ",".join(A)
  A_new = A_string.replace(B[i],C[i])
  A =  A_new.split(",")
  int_A = [int(n) for n in A]
  print(sum(int_A))

Fixed submission:
import collections
import copy
N=int(input())
A=list(map(int,(input().split())))
ans=sum(A)
Q=int(input())
col = collections.Counter(A)

for i in range(Q):
  L, R = map(int,(input().split()))
  sa=(R-L)*col[L]
  col[R]+=copy.copy(col[L])
  col[L]=0
  ans= ans+sa
  print(ans)