Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
from collections import Counter as C

n=int(input())
a = list(input().split())
a = [int(i) for i in a]
q=int(input())
bc=[list(map(int,input().split())) for i in range(q)]
bc=np.array(bc).T
b=bc[0]
c=bc[1]

d=C(a)
d2={}
for k,v in d.items():
  d2[k]=k*v

#print(d)
ans=sum(d2.values())
for i in range(q):
  #print(d2)
  if d.get(b[i]):
    #removed=d.pop(b[i])
    _=d2.pop(b[i])
    d[c[i]]+=d[b[i]]
    d2[c[i]]=c[i]*d[c[i]]
    d[b[i]]=0
  else:
    pass
  #print((np.array(list(d2.values()))))
  #ans+=(c[i]-b[i])*d[removed]
  print(sum(d2.values()))


Fixed submission:
import numpy as np
from collections import Counter as C

n=int(input())
a = list(input().split())
a = [int(i) for i in a]
q=int(input())
bc=[list(map(int,input().split())) for i in range(q)]
bc=np.array(bc).T
b=bc[0]
c=bc[1]

d=C(a)
d2={}
for k,v in d.items():
  d2[k]=k*v

#print(d)
ans=sum(a)
for i in range(q):
  d[c[i]]+=d[b[i]]
  ans+=(c[i]-b[i])*d[b[i]]
  d[b[i]]=0
  print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np
from collections import Counter as C

n=int(input())
a = list(input().split())
a = [int(i) for i in a]
q=int(input())
bc=[list(map(int,input().split())) for i in range(q)]
bc=np.array(bc).T
b=bc[0]
c=bc[1]

d=C(a)
d2={}
for k,v in d.items():
  d2[k]=k*v

#print(d)
ans=sum(d2.values())
for i in range(q):
  #print(d2)
  
  if d.get(b[i]):
    removed=d.pop(b[i])
    _=d2.pop(b[i])
    d[c[i]]+=removed
    d2[c[i]]=c[i]*d[c[i]]
  else:
    pass
  #print((np.array(list(d2.values()))))
  ans+=(c[i]-b[i])*removed
  print(ans)


Fixed submission:
import numpy as np
from collections import Counter as C

n=int(input())
a = list(input().split())
a = [int(i) for i in a]
q=int(input())
bc=[list(map(int,input().split())) for i in range(q)]
bc=np.array(bc).T
b=bc[0]
c=bc[1]

d=C(a)
d2={}
for k,v in d.items():
  d2[k]=k*v

#print(d)
ans=sum(a)
for i in range(q):
  d[c[i]]+=d[b[i]]
  ans+=(c[i]-b[i])*d[b[i]]
  d[b[i]]=0
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
from collections import Counter as C

n=int(input())
a = list(input().split())
a = [int(i) for i in a]
q=int(input())
bc=[list(map(int,input().split())) for i in range(q)]
bc=np.array(bc).T
b=bc[0]
c=bc[1]

d=C(a)
d2={}
for k,v in d.items():
  d2[k]=k*v

#print(d)
for i in range(q):
  #print(d2)
  if d.get(b[i]):
    removed=d.pop(b[i])
    _=d2.pop(b[i])
    d[c[i]]+=removed
    d2[c[i]]=c[i]*d[c[i]]
  else:
    pass
  #print((np.array(list(d2.values()))))
  print(np.sum(np.array(list(d2.values()))))
  


Fixed submission:
import numpy as np
from collections import Counter as C

n=int(input())
a = list(input().split())
a = [int(i) for i in a]
q=int(input())
bc=[list(map(int,input().split())) for i in range(q)]
bc=np.array(bc).T
b=bc[0]
c=bc[1]

d=C(a)
d2={}
for k,v in d.items():
  d2[k]=k*v

#print(d)
ans=sum(a)
for i in range(q):
  d[c[i]]+=d[b[i]]
  ans+=(c[i]-b[i])*d[b[i]]
  d[b[i]]=0
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
from collections import Counter as C

n=int(input())
a = list(input().split())
a = [int(i) for i in a]
q=int(input())
bc=[list(map(int,input().split())) for i in range(q)]
bc=np.array(bc).T
b=bc[0]
c=bc[1]

d=C(a)
d2={}
for k,v in d.items():
  d2[k]=k*v

#print(d)
for i in range(q):
  #print(d2)
  if d.get(b[i]):
    removed=d.pop(b[i])
    _=d2.pop(b[i])
    d[c[i]]+=removed
    d2[c[i]]=c[i]*d[c[i]]
  else:
    pass
  print(sum(d2.values()))
  


Fixed submission:
import numpy as np
from collections import Counter as C

n=int(input())
a = list(input().split())
a = [int(i) for i in a]
q=int(input())
bc=[list(map(int,input().split())) for i in range(q)]
bc=np.array(bc).T
b=bc[0]
c=bc[1]

d=C(a)
d2={}
for k,v in d.items():
  d2[k]=k*v

#print(d)
ans=sum(a)
for i in range(q):
  d[c[i]]+=d[b[i]]
  ans+=(c[i]-b[i])*d[b[i]]
  d[b[i]]=0
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
from collections import Counter as C

n=int(input())
a = list(input().split())
a = [int(i) for i in a]
q=int(input())
bc=[list(map(int,input().split())) for i in range(q)]
bc=np.array(bc).T
b=bc[0]
c=bc[1]

d=C(a)
d2={}
for k,v in d.items():
  d2[k]=k*v

#print(d)
for i in range(q):
  ans=0
  #print(d2)
  for k,v in d.items():
    if k==b[i]:
      #print("b[i]",b[i])
      removed=d.pop(b[i])
      no=d2.pop(b[i])
      d[c[i]]+=removed
      d2[c[i]]=c[i]*d[c[i]]
      break
  print(sum(d2.values()))
  


Fixed submission:
import numpy as np
from collections import Counter as C

n=int(input())
a = list(input().split())
a = [int(i) for i in a]
q=int(input())
bc=[list(map(int,input().split())) for i in range(q)]
bc=np.array(bc).T
b=bc[0]
c=bc[1]

d=C(a)
d2={}
for k,v in d.items():
  d2[k]=k*v

#print(d)
ans=sum(a)
for i in range(q):
  d[c[i]]+=d[b[i]]
  ans+=(c[i]-b[i])*d[b[i]]
  d[b[i]]=0
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
from collections import Counter as C

n=int(input())
a = list(input().split())
a = [int(i) for i in a]
q=int(input())
bc=[list(map(int,input().split())) for i in range(q)]
bc=np.array(bc).T
b=bc[0]
c=bc[1]

d=C(a)
#print(d)
for i in range(q):
  ans=0
  for k,v in d.items():
    if k==b[i]:
      removed=d.pop(b[i])
      d[c[i]]+=removed
      break
  #print(d)
  for k,v in d.items():
    #print(ans,k,v)
    ans+=k*v
  print(ans)
  

Fixed submission:
import numpy as np
from collections import Counter as C

n=int(input())
a = list(input().split())
a = [int(i) for i in a]
q=int(input())
bc=[list(map(int,input().split())) for i in range(q)]
bc=np.array(bc).T
b=bc[0]
c=bc[1]

d=C(a)
d2={}
for k,v in d.items():
  d2[k]=k*v

#print(d)
ans=sum(a)
for i in range(q):
  d[c[i]]+=d[b[i]]
  ans+=(c[i]-b[i])*d[b[i]]
  d[b[i]]=0
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n=int(input())
a = list(input().split())
a = [int(i) for i in a]
q=int(input())
bc=[list(map(int,input().split())) for i in range(q)]
bc=np.array(bc).T
b=bc[0]
c=bc[1]

ans=sum(a)
for i in range(q):
  #print(a)
  count=a.count(b[i])
  ans+=(c[i]-b[i])*count
  print(ans)
  a=[c[i] if b[i]==a[ii] else a[ii] for ii in range(n)]
  
  

Fixed submission:
import numpy as np
from collections import Counter as C

n=int(input())
a = list(input().split())
a = [int(i) for i in a]
q=int(input())
bc=[list(map(int,input().split())) for i in range(q)]
bc=np.array(bc).T
b=bc[0]
c=bc[1]

d=C(a)
d2={}
for k,v in d.items():
  d2[k]=k*v

#print(d)
ans=sum(a)
for i in range(q):
  d[c[i]]+=d[b[i]]
  ans+=(c[i]-b[i])*d[b[i]]
  d[b[i]]=0
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n=int(input())
a = list(input().split())
a = [int(i) for i in a]
q=int(input())
bc=[list(map(int,input().split())) for i in range(q)]
bc=np.array(bc).T
b=bc[0]
c=bc[1]

for i in range(q):
  a=[c[i] if b[i]==a[ii] else a[ii] for ii in range(n)]
  #print(a)
  print(sum(a))
  

Fixed submission:
import numpy as np
from collections import Counter as C

n=int(input())
a = list(input().split())
a = [int(i) for i in a]
q=int(input())
bc=[list(map(int,input().split())) for i in range(q)]
bc=np.array(bc).T
b=bc[0]
c=bc[1]

d=C(a)
d2={}
for k,v in d.items():
  d2[k]=k*v

#print(d)
ans=sum(a)
for i in range(q):
  d[c[i]]+=d[b[i]]
  ans+=(c[i]-b[i])*d[b[i]]
  d[b[i]]=0
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a = list(input().split())
a = [int(i) for i in a]
q=int(input())
#bc=[list(map(int,input().split())) for i in range(q)]

for _ in range(q):
  bi,ci=map(int,input().split())
  a=[ci if bi==a[i] else a[i] for i in range(n)]
  #print(a)
  print(sum(a))
  

Fixed submission:
import numpy as np
from collections import Counter as C

n=int(input())
a = list(input().split())
a = [int(i) for i in a]
q=int(input())
bc=[list(map(int,input().split())) for i in range(q)]
bc=np.array(bc).T
b=bc[0]
c=bc[1]

d=C(a)
d2={}
for k,v in d.items():
  d2[k]=k*v

#print(d)
ans=sum(a)
for i in range(q):
  d[c[i]]+=d[b[i]]
  ans+=(c[i]-b[i])*d[b[i]]
  d[b[i]]=0
  print(ans)