Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n = int(input())
a = np.array([int(i) for i in input().split()])
q = int(input())
hako = np.array([0]*(10**6))
ind = np.array(list(range(10**6)))
s = []

for i in a:
    hako[i] += 1

for i in range(q):
    b, c = [int(i) for i in input().split()]
#     S += (ind[c] - ind[b])*hako[b]
    hako[c] += hako[b]
    hako[b] = 0
    S = np.sum(hako*ind)
    s.append(S)
for i in range(q):
    print(s[i])

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
q = int(input())
hako = [0]*(10**6)
ind = list(range(10**6))
S = sum(a)
s = []

for i in a:
    hako[i] += 1

for i in range(q):
    b, c = [int(i) for i in input().split()]
    S += (ind[c] - ind[b])*hako[b]
    s.append(S)
    hako[c] += hako[b]
    hako[b] = 0
for i in range(q):
    print(s[i])

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(i) for i in input().split()]
q = int(input())
hako = [0]*(10^6+1)
ind = list(range(10^6+1))
S = sum(a)
s = []

for i in a:
    hako[i] += 1

for i in range(q):
    b, c = [int(i) for i in input().split()]
    S += (ind[c] - ind[b])*hako[b]
    s.append(S)
    hako[c] += hako[b]
    hako[b] = 0
for i in range(q):
    print(s[i])

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
q = int(input())
hako = [0]*(10**6)
ind = list(range(10**6))
S = sum(a)
s = []

for i in a:
    hako[i] += 1

for i in range(q):
    b, c = [int(i) for i in input().split()]
    S += (ind[c] - ind[b])*hako[b]
    s.append(S)
    hako[c] += hako[b]
    hako[b] = 0
for i in range(q):
    print(s[i])

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(i) for i in input().split()]
q = int(input())
hako = [0]*(max(a)+1)
ind = list(range(max(a)+1))
S = sum(a)
s = []

for i in a:
    hako[i] += 1

for i in range(q):
    b, c = [int(i) for i in input().split()]
    S += (ind[c] - ind[b])*hako[b]
    s.append(S)
    hako[c] += hako[b]
    hako[b] = 0
for i in range(q):
    print(s[i])

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
q = int(input())
hako = [0]*(10**6)
ind = list(range(10**6))
S = sum(a)
s = []

for i in a:
    hako[i] += 1

for i in range(q):
    b, c = [int(i) for i in input().split()]
    S += (ind[c] - ind[b])*hako[b]
    s.append(S)
    hako[c] += hako[b]
    hako[b] = 0
for i in range(q):
    print(s[i])

Buggy python submission (verdict: Runtime Error):
import numpy as np

n = int(input())
a = np.array([int(i) for i in input().split()])
q = int(input())
hako = np.array([0]*(a.max()+1))
ind = np.array(list(range(a.max()+1)))
S = []

for i in a:
    hako[i] += 1

for i in range(q):
    b, c = [int(i) for i in input().split()]
    hako[c] += hako[b]
    hako[b] = 0
    S.append(np.sum(ind*hako))
for i in range(q):
    print(S[i])

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
q = int(input())
hako = [0]*(10**6)
ind = list(range(10**6))
S = sum(a)
s = []

for i in a:
    hako[i] += 1

for i in range(q):
    b, c = [int(i) for i in input().split()]
    S += (ind[c] - ind[b])*hako[b]
    s.append(S)
    hako[c] += hako[b]
    hako[b] = 0
for i in range(q):
    print(s[i])

Buggy python submission (verdict: Runtime Error):
import numpy as np

n = int(input())
a = np.array([int(i) for i in input().split()])
q = int(input())
hako = np.array([0]*(10^6))
ind = np.array(list(range(10^6)))
S = []

for i in a:
    hako[i] += 1

for i in range(q):
    b, c = [int(i) for i in input().split()]
    hako[c] += hako[b]
    hako[b] = 0
    S.append(np.sum(ind*hako))
for i in range(q):
    print(S[i])

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
q = int(input())
hako = [0]*(10**6)
ind = list(range(10**6))
S = sum(a)
s = []

for i in a:
    hako[i] += 1

for i in range(q):
    b, c = [int(i) for i in input().split()]
    S += (ind[c] - ind[b])*hako[b]
    s.append(S)
    hako[c] += hako[b]
    hako[b] = 0
for i in range(q):
    print(s[i])

Buggy python submission (verdict: Runtime Error):
import numpy as np
n = int(input())
a = np.array([int(i) for i in input().split()])
q = int(input())
hako = np.array([0]*(10^6))
ind = np.array(list(range(10^6)))
S = []

for i in a:
    hako[i] += 1

for i in range(q):
    b, c = [int(i) for i in input().split()]
    hako[c] += hako[b]
    hako[b] = 0
    S.append(np.sum(ind*hako))
for i in range(q):
    print(S[i])

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
q = int(input())
hako = [0]*(10**6)
ind = list(range(10**6))
S = sum(a)
s = []

for i in a:
    hako[i] += 1

for i in range(q):
    b, c = [int(i) for i in input().split()]
    S += (ind[c] - ind[b])*hako[b]
    s.append(S)
    hako[c] += hako[b]
    hako[b] = 0
for i in range(q):
    print(s[i])

Buggy python submission (verdict: Runtime Error):
import numpy as np
n = int(input())
a = np.array([int(i) for i in input().split()])
q = int(input())
hako = np.array([0]*(10^5+1))
ind = np.array(list(range(10^5+1)))
S = []

for i in a:
    hako[i] += 1

for i in range(q):
    b, c = [int(i) for i in input().split()]
    hako[c] += hako[b]
    hako[b] = 0
    S.append(np.sum(ind*hako))
for i in range(q):
    print(S[i])

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
q = int(input())
hako = [0]*(10**6)
ind = list(range(10**6))
S = sum(a)
s = []

for i in a:
    hako[i] += 1

for i in range(q):
    b, c = [int(i) for i in input().split()]
    S += (ind[c] - ind[b])*hako[b]
    s.append(S)
    hako[c] += hako[b]
    hako[b] = 0
for i in range(q):
    print(s[i])

Buggy python submission (verdict: Runtime Error):
import numpy as np
n = int(input())
a = np.array([int(i) for i in input().split()])
q = int(input())
hako = np.array([0]*(10^5+1))
ind = np.array(list(range(10^5+1)))
S = []

for i in a:
    hako[i] += 1

for i in range(q):
    b, c = [int(i) for i in input().split()]
    hako[c] += hako[b]
    hako[b] = 0
    S.append(np.sum(ind*hako))
for i in range(q):
    print(S[i])

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
q = int(input())
hako = [0]*(10**6)
ind = list(range(10**6))
S = sum(a)
s = []

for i in a:
    hako[i] += 1

for i in range(q):
    b, c = [int(i) for i in input().split()]
    S += (ind[c] - ind[b])*hako[b]
    s.append(S)
    hako[c] += hako[b]
    hako[b] = 0
for i in range(q):
    print(s[i])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n = int(input())
a = np.array([int(i) for i in input().split()])
q = int(input())
S = []

for i in range(q):
    b, c = [int(i) for i in input().split()]
    a = np.where(a == b, c, a)
    S.append(np.sum(a))
    
for i in range(q):
    print(S[i])

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
q = int(input())
hako = [0]*(10**6)
ind = list(range(10**6))
S = sum(a)
s = []

for i in a:
    hako[i] += 1

for i in range(q):
    b, c = [int(i) for i in input().split()]
    S += (ind[c] - ind[b])*hako[b]
    s.append(S)
    hako[c] += hako[b]
    hako[b] = 0
for i in range(q):
    print(s[i])