Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
number=list(map(int,input().split()))
sum_number=sum(number)
Q=int(input())
number_count=[0]*100001
for i in range(100001):
    number_count[i]=number.count(i)

for _ in range(Q):
    B,C=map(int,input().split())
    sum_number += (C-B)*number_count[B]
    number_count[C] += number_count[B]
    number_count[B] = 0
    print(sum_number)


Fixed submission:
from collections import Counter
N=int(input())
number=list(map(int,input().split()))
sum_number=sum(number)
Q=int(input())
number_count=Counter(number)


for _ in range(Q):
    B,C=map(int,input().split())
    sum_number += (C-B)*number_count[B]
    number_count[C] += number_count[B]
    number_count[B] = 0
    print(sum_number)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
number=list(map(int,input().split()))
sum_number=sum(number)
Q=int(input())
number_count=[0]*100001
for i in range(100001):
    number_count[i]=number.count(i)

for _ in range(Q):
    B,C=map(int,input().split())
    sum_number += (C-B)*number_count[B]
    number_count[C] += number_count[B]
    number_count[B] -= number_count[B]
    print(sum_number)


Fixed submission:
from collections import Counter
N=int(input())
number=list(map(int,input().split()))
sum_number=sum(number)
Q=int(input())
number_count=Counter(number)


for _ in range(Q):
    B,C=map(int,input().split())
    sum_number += (C-B)*number_count[B]
    number_count[C] += number_count[B]
    number_count[B] = 0
    print(sum_number)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
number=list(map(int,input().split()))
sum_number=sum(number)
Q=int(input())
number_count=[0]*100001
for i in range(100001):
    number_count[i]=number.count(i)

for _ in range(Q):
    B,C=map(int,input().split())
    sum_number += (C-B)*number_count[B]
    number_count[C] += number_count[B]
    number_count[B] -= number_count[B]
    print(sum_number)


Fixed submission:
from collections import Counter
N=int(input())
number=list(map(int,input().split()))
sum_number=sum(number)
Q=int(input())
number_count=Counter(number)


for _ in range(Q):
    B,C=map(int,input().split())
    sum_number += (C-B)*number_count[B]
    number_count[C] += number_count[B]
    number_count[B] = 0
    print(sum_number)

Buggy python submission (verdict: Runtime Error):
N=int(input())
number=list(map(int,input().split()))
sum_number=sum(number)
Q=int(input())
number_count=[0]*100000
for i in range(100000):
    number_count[i]=number.count(i)

for _ in range(Q):
    B,C=map(int,input().split())
    sum_number += (C-B)*number_count[B]
    number_count[C] += number_count[B]
    number_count[B] -= number_count[B]
    print(sum_number)


Fixed submission:
from collections import Counter
N=int(input())
number=list(map(int,input().split()))
sum_number=sum(number)
Q=int(input())
number_count=Counter(number)


for _ in range(Q):
    B,C=map(int,input().split())
    sum_number += (C-B)*number_count[B]
    number_count[C] += number_count[B]
    number_count[B] = 0
    print(sum_number)

Buggy python submission (verdict: Runtime Error):
N=int(input())
number=list(map(int,input().split()))
sum_number=sum(number)
Q=int(input())
number_count=[0]*100000
for i in range(100000):
    number_count[i]=number.count(i)

for j in range(Q):
    B,C=map(int,input().split())
    sum_number += (C-B)*number_count[B]
    number_count[C] += number_count[B]
    number_count[B] -= number_count[B]
    print(sum_number)


Fixed submission:
from collections import Counter
N=int(input())
number=list(map(int,input().split()))
sum_number=sum(number)
Q=int(input())
number_count=Counter(number)


for _ in range(Q):
    B,C=map(int,input().split())
    sum_number += (C-B)*number_count[B]
    number_count[C] += number_count[B]
    number_count[B] = 0
    print(sum_number)

Buggy python submission (verdict: Runtime Error):
N=int(input())
number=list(map(int,input().split()))
sum_number=sum(number)
Q=int(input())
number_count=[0]*100000
for i in range(100000):
    number_count[i]=number.count(i)

for j in range(Q):
    B,C=map(int,input().split())
    sum_number += (C-B)*number_count[B]
    number_count[C] += number_count[B]
    number_count[B] -= number_count[B]
    print(sum_number)


Fixed submission:
from collections import Counter
N=int(input())
number=list(map(int,input().split()))
sum_number=sum(number)
Q=int(input())
number_count=Counter(number)


for _ in range(Q):
    B,C=map(int,input().split())
    sum_number += (C-B)*number_count[B]
    number_count[C] += number_count[B]
    number_count[B] = 0
    print(sum_number)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
number=list(map(int,input().split()))
Q=int(input())
for i in range(Q):
    B,C=map(int,input().split())
    if B in number:
        for i in range(N):
            if number[i]==B:
                number[i]=C
    print(sum(number))

Fixed submission:
from collections import Counter
N=int(input())
number=list(map(int,input().split()))
sum_number=sum(number)
Q=int(input())
number_count=Counter(number)


for _ in range(Q):
    B,C=map(int,input().split())
    sum_number += (C-B)*number_count[B]
    number_count[C] += number_count[B]
    number_count[B] = 0
    print(sum_number)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
number=list(map(int,input().split()))
Q=int(input())
for i in range(Q):
    B,C=map(int,input().split())
    if B in number:
        for i in range(N):
            if number[i]==B:
                number[i]=C
    print(sum(number))

Fixed submission:
from collections import Counter
N=int(input())
number=list(map(int,input().split()))
sum_number=sum(number)
Q=int(input())
number_count=Counter(number)


for _ in range(Q):
    B,C=map(int,input().split())
    sum_number += (C-B)*number_count[B]
    number_count[C] += number_count[B]
    number_count[B] = 0
    print(sum_number)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
number=list(map(int,input().split()))
Q=int(input())
for i in range(Q):
    B,C=map(int,input().split())
    if B in number:
        for i in range(N):
            if number[i]==B:
                number[i]=C
    print(sum(number))

Fixed submission:
from collections import Counter
N=int(input())
number=list(map(int,input().split()))
sum_number=sum(number)
Q=int(input())
number_count=Counter(number)


for _ in range(Q):
    B,C=map(int,input().split())
    sum_number += (C-B)*number_count[B]
    number_count[C] += number_count[B]
    number_count[B] = 0
    print(sum_number)