Harryxun/stf_run huggingface dataset:
n,k,q = map(int,input().split())
l = [0 for x in range(n)]
for _ in range(q):
    l[int(input())] += 1

ans = []
for i in l:
    if k- q + i > 0:
        ans.append("Yes")
    else:
        ans.append("No")
print("\n".join(ans))

### FIXED CODE ###

n,k,q = map(int,input().split())
l = [0 for x in range(n)]
for _ in range(q):
    l[int(input())-1] += 1

ans = []
for i in l:
    if k- q + i > 0:
        ans.append("Yes")
    else:
        ans.append("No")
print("\n".join(ans))
MOD = 10**9+7
N = int(input())
A = list(map(int, input().split()))

l = 1
for a in A:
    l = lcm(l, a)

l %= MOD

ans = 0
for a in A:
    ans += l * pow(a, MOD-2, MOD)
    ans %= MOD

print(int(ans))


### FIXED CODE ###

from fractions import gcd

mod = 10 ** 9 + 7

N = int(input())
A = list(map(int, input().split()))

lcm = 1
for s in A:
    lcm = s * lcm // gcd(lcm, s)

ans = lcm * sum([pow(s, mod - 2, mod) for s in A]) % mod

print(int(ans % mod))
a, b, k = input().split()
a = int(a)
b = int(b)
k = int(k)
a_list = []
b_list = []
for i in range(1, a):
    i
    if a % i == 0:
        a_list.append(i)

for i in range(1, b):
    i
    if b % i == 0:
        b_list.append(i)

a_list.extend(b_list)
co_divisor = list(set(a_list))
print(co_divisor[k-1])

### FIXED CODE ###

a, b, k = input().split()
a = int(a)
b = int(b)
k = int(k)
a_list = []
b_list = []
for j in range(a):
    i = j + 1
    if a % i == 0:
        a_list.append(i)
for j in range(b):
    i = j + 1
    if b % i == 0:
        b_list.append(i)

#a_list.extend(b_list)
#co_divisor = list(set(a_list))
a_list = set(a_list)
b_list = set(b_list)
co_divisor = list(a_list & b_list)
co_divisor.sort(reverse=True)
print(co_divisor[k-1])
import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
sys.setrecursionlimit(4100000)
from functools import lru_cache
INF = 1 << 60

#ここから書き始める
n, m = map(int, input().split())
a = [[""] * n] * n
b = [[""] * m] * m
for i in range(n):
    a[i] = [j for j in input()]
for i in range(m):
    b[i] = [j for j in input()]
# print(a)
# print(b)
for i in range(n - m):
    for j in range(n - m):
        flag = True
        for k in range(i + m):
            for l in range(j + m):
                if a[k][l] != b[k][l]:
                    flag = False
                    break
            if not flag:
                break
        if flag:
            print("Yes")
            sys.exit()
print("No")



### FIXED CODE ###

import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
sys.setrecursionlimit(4100000)
from functools import lru_cache
INF = 1 << 60

#ここから書き始める
n, m = map(int, input().split())
a = [[""] * n] * n
b = [[""] * m] * m
for i in range(n):
    a[i] = [j for j in input()]
for i in range(m):
    b[i] = [j for j in input()]
# print(a)
# print(b)
for i in range(n - m + 1):
    for j in range(n - m + 1):
        flag = True
        for k in range(i, i + m):
            for l in range(j, j + m):
                if a[k][l] != b[k - i][l - j]:
                    flag = False
                    break
            if not flag:
                break
        if flag:
            print("Yes")
            sys.exit()
print("No")
import math
a,b = map(float, input().split())
print(math.floor((a*(b*100))/100)

### FIXED CODE ###

a,b = input().split()
intA = int(a)
intB = int(b.replace(".",""))
print(intA*intB // 100)
x = input()
yyyy, mm, dd = x.split("/")
if mm <= 4:
  print("Heisei")
else:
  print("TBD")
  

### FIXED CODE ###

x = input()
yyyy, mm, dd = x.split("/")
if int(mm) <= 4:
  print("Heisei")
else:
  print("TBD")
input = sys.stdin.readline
N, Q = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N-1)]
P = [0] * Q
X = [0] * Q
V = [0] * (N + 1)
for i in range(Q):
    P, X = map(int, input().split())
    V[P] += X

### FIXED CODE ###

from collections import deque

N, Q = map(int, input().split())
AB = {i: set() for i in range(1, N+1)}
for i in range(N - 1):
    tmpA, tmpB = map(int, input().split())
    AB[tmpA].add(tmpB)
    AB[tmpB].add(tmpA)
P = [0] * Q
X = [0] * Q
V = [0] * (N + 1)
for i in range(Q):
    P, X = map(int, input().split())
    V[P] += X

check = [0]*(N + 1)
q = deque()
q.append(1)
check[1] = 1
while q != deque():
    node = q.pop()
    for i in AB[node]:
        if check[i] == 1:
            continue
        V[i] += V[node]
        check[i] = 1
        q.appendleft(i)
print(*V[1:])
N,C = map(int,input().split())
STC = []
for _ in range(N):
  s,t,c = map(int,input().split())
  STC.append([s,t,c])
STC.sort()

rs = [[STC[0][1],STC[0][2]]]
for i in range(1,N):
  len_rs = len(rs)
  
  min_idx = None
  for j in range(len_rs):
    if rs[j][1] != STC[i][2]: tmp_stc_r = STC[i][0] - 0.5
    else: tmp_stc_r = STC[i][0]
 
    if rs[j][0] <= tmp_stc_r:
      if min_idx is None: min_idx = j
      else:
        if rs[j][0] < rs[min_idx][0]: min_idx = j

  if min_idx is None: rs.append([STC[i][1], STC[i][2]])
  else: rs[min_idx] = [STC[i][1], STC[i][2]]
  
print(len(rs))

### FIXED CODE ###

N,A,B = map(int,input().split())
print(min(B,A*N))
import math
from functools import reduce
import itertools

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())
ans = 0

seq = [i for i in range(1, k+1)]
b = list(itertools.combinations_with_replacement(seq,3))

for a in b:
    if a[0] == a[1] == a[2]:
        ans += gcd(a[0], a[1], a[2])
    else:
        ans += gcd(a[0], a[1], a[2])*(n+1)
print(ans)

### FIXED CODE ###

from math import gcd
 
n = int(input())
 
ans = 0
 
for i in range(1,n+1):
  for j in range(1,n+1):
    for k in range(1,n+1):
      ans += gcd(gcd(i,j),k)
      
print(ans)
s = input()
if s.endswith(2) == True or s.endswith(4) ==True or s.endswitch(5) == True or s.endswith(7) == True or s.endswith(9) == True:
  
  print('hon')
elif s.endswith(0) == True or s.endswith(1) == True or s.endswitch(6) == True or s.endswitch(8) == True:
  print('pon')
else:
  print('bon')


### FIXED CODE ###

s = input()
n = len(s)
a = s[n-1:n]
if a == '2' or a == '4' or a == '5' or a == '7' or a == '9':
  print('hon')
elif a == '0' or a == '1' or a == '6' or a == '8':
  print('pon')
else:
  print('bon')
a = [0] * (10 ** 9)

### FIXED CODE ###

a,b = map(int, input().split())
if a >= 13:
  print(b)
elif 6 <= a <= 12:
  print(b//2)
else:
  print(0)
a = str(input())
b = str(input())
a.sort()
b.sort()
if a < b:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

a = list(str(input()))
b = list(str(input()))
a.sort()
b.sort(reverse=True)
c = "".join(a)
d = "".join(b)
if c < d:
  print("Yes")
else:
  print("No")
import sys
a=list(input())
b=''
c=0
for i in range(4):
  if b=a[i]:
    c+=1
    if c>=2:
      print('Bad')
    else:
      print('Good')
    
  else:
    pass
  c=0
print('Bad')


### FIXED CODE ###

a=input()
if a[0]==a[1] or a[1]==a[2] or a[2]==a[3]:
  print('Bad')
else:
  print('Good')
N=int(input())
T_N=int(input().split())
list_time=[]
for i in range(N):
    list_time.append(T_N[i])
#Ti秒の総和を求める
sum=sum(list_time)
M=int(input())
for i in range(M):
    p,x=map(int,input.split())
    #ドリンク飲んだ時と飲まないときの差を元の合計に足す。
    ans=sum+(x-list_time[p-1])
    print(ans)

### FIXED CODE ###

n = int(input())
t_N = input().split()
list_Time = []
for id in range(n):
    list_Time.append(int(t_N[id]))
sum = sum(list_Time)
m = int(input())
for id in range(m):
    p, x = map(int, input().split())
    answer = sum + x - list_Time[p - 1]
    print(answer)
n = int(input())
li = list(map(int, input().split()))

for i in range(n):
    li.sort()
    a =  li[i]
    b = li[int((n+1)/2)]
    print(b)
    li.append(a)

### FIXED CODE ###

x,y,z=map(int,input().split())
if x <= z <= x+y :
  print("YES")
else:
  print("NO")
p_num = int(input())
p = list(map(int,input().split()))

count = 1
min = List[0]


for i in List[1:]:
    if i < min_num:
        min_num = i
        count += 1
        

print(count)


### FIXED CODE ###

p_num = int(input())
p = list(map(int,input().split()))

count = 1
min_num = p[0]


for i in p[1:]:
    if i < min_num:
        min_num = i
        count += 1
        

print(count)
n,a,b = map(int, input().split())

s=0
for i in range(N+1):
    x = i
    m = 0
    while x:
        m += x % 10
        x //= 10
    if a <= m <= b:
        s += i
print(s)

### FIXED CODE ###

#SomeSums
n,a,b = map(int, input().split())

s=0
for i in range(n+1):
    x = i
    m = 0
    while x:
        m += x % 10
        x //= 10
    if a <= m <= b:
        s += i
print(s)
r, c = map(int, raw_input().split())
a = [[0 for i in range(r)] for j in range(c)]
for i in range(c):
    row = map(int, raw_input().split())
    for j in range(r):
        a[i][j] = row[j]

### FIXED CODE ###

r, c = map(int, raw_input().split())
ss = []
for i in range(r):
    ss.append(map(int, raw_input().split()))
    ss[i].append(sum(ss[i]))
    print ' '.join(map(str, ss[i]))
ss.append([])
for j in range(c+1):
    csum = 0
    for i in range(r):
        csum += ss[i][j]
    ss[r].append(csum)
print ' '.join(map(str, ss[r]))
#!/usr/bin/env python3
import sys
from functools import reduce
import math

MOD = 1000000007  # type: int

GCD_CACHE = {}


def gcd(x, y):
    if (x, y) in GCD_CACHE:
        return GCD_CACHE[(x, y)]
    d = math.gcd(x, y)
    GCD_CACHE[(x, y)] = d
    return d


def lcm_base(x, y):
    return (x * y) // gcd(x, y)


def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)


def solve(N: int, A: "List[int]"):
    m = lcm(*A) % MOD
    sum = 0
    for a in A:
        sum = (sum + m*pow(a, MOD-2, MOD)) % MOD
    print(sum)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
from functools import reduce
import fractions

MOD = 1000000007  # type: int

GCD_CACHE = {}


def gcd(x, y):
    if (x, y) in GCD_CACHE:
        return GCD_CACHE[(x, y)]
    d = fractions.gcd(x, y)
    GCD_CACHE[(x, y)] = d
    return d


def lcm_base(x, y):
    return (x * y) // gcd(x, y)


def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)


def solve(N: int, A: "List[int]"):
    m = lcm(*A) % MOD
    sum = 0
    for a in A:
        sum = (sum + m*pow(a, MOD-2, MOD)) % MOD
    print(sum)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()
from collections import Counter

n = int(input())
a = list(map(int, input().split()))

c = Counter(a)  # リストの要素をカウント
cnt = [k for k, v in c.imtes() if v >= 2]

if len(cnt) < 2:
    print(0)
else:
    cnt = sorted(cnt, reverse=True)
    if c[cnt[0]] >= 4:
        print(cnt[0] * cnt[0])
    else:
        print(cnt[0] * cnt[1])

### FIXED CODE ###

from collections import Counter

n = int(input())
a = list(map(int, input().split()))

c = Counter(a)  # リストの要素をカウント
cnt = [k for k, v in c.items() if v >= 2]

if len(cnt) < 2:
    print(0)
else:
    cnt = sorted(cnt, reverse=True)
    if c[cnt[0]] >= 4:
        print(cnt[0] * cnt[0])
    else:
        print(cnt[0] * cnt[1])
n = int(input())
table = [input() for i in range(n)]
print("{} {} {}".format(max(table[n]),min(table[n]),sum(table[n])))


### FIXED CODE ###

n = input()
table = list(map(int,input().split()))
print("{} {} {}".format(min(table),max(table),sum(table)))
N = int(input()) 
A=list(map(int,input().split())) 
i=0 
s=[] 
for i in range(N): 
    s.append(0) 
for i in range(N): 
    s[i]=A.count(i+1) 
for i in range(N): 
    print(s[i])

### FIXED CODE ###

import math
a = int(input())
print(2*a*math.pi)
import math
import itertools
import heapq
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect, bisect_left, bisect_right
from collections import defaultdict, deque


# d = defaultdict(lambda: 0)
# setrecursionlimit(10**7)
# inf = float("inf")


##### stdin ####
def LM(t, r): return list(map(t, r))
def R(): return stdin.readline()
def RS(): return R().split()
def I(): return int(R())
def F(): return float(R())
def LI(): return LM(int,RS())
def LF(): return LM(float,RS())
def ONE_SL(): return list(input())
def ONE_IL(): return LM(int, ONE_SL())
def ALL_I(): return map(int, stdin)
def ALL_IL(): return LM(int,stdin)

##### tools #####
def ap(f): return f.append
def pll(li): print('\n'.join(LM(str,li)))
def pljoin(li, s): print(s.join(li))



##### main #####

class BIT(object):

	def __init__(self,l):
		self.size = l
		self.bit = [0]* (self.size+1)

	def sum(self, i):
		s = 0
		while i > 0:
			s += self.bit[i]
			i -= i & -i
		return s

	def add(self, i, x):
		while i < self.size:
			self.bit[i] += x
			i += i & -i

	def __str__(self):
		return str(self.bit)


def main():
	N,M = LI()

	bit = BIT(M+2)
	L = []
	R = []
	b = [[] for i in range(M+1)]


	for i in range(N):
		l,r = LI()
		L.append(l); R.append(r)
		b[r-l +1].append(i)
	b = []

	gone = 0
	for d in range(1, M+1):
		for i in b[d]:
			gone+=1
			bit.add(L[i], 1)
			bit.add(R[i]+1, -1)


		ans = N-gone

		for m in range(d, M+1, d):

			ans += bit.sum(m)
		print(ans)




if __name__ == '__main__':
	main()

### FIXED CODE ###

from math import ceil
def main(): print(ceil((int(input())-6)/11*2)+1)
if __name__ == "__main__": main()
import collections
import functools
import time

class memoized(object):
    def __init__(self, func):
       self.func = func
       self.cache = {}

    def __call__(self, *args):
       if not isinstance(args, collections.Hashable):
          return self.func(*args)

       if args in self.cache:
          return self.cache[args]

       else:
          value = self.func(*args)
          self.cache[args] = value
          return value

    def __repr__(self):
       return self.func.__doc__

    def __get__(self, obj, objtype):
       return functools.partial(self.__call__, obj)

def knapsack(items, maxweight):
    @memoized
    def bestvalue(i, j):
        if i == 0: return 0
        value, weight = items[i - 1]
        if weight > j:
            return bestvalue(i - 1, j)
        else:
            return max(bestvalue(i - 1, j),
                       bestvalue(i - 1, j - weight) + value)

    j = maxweight
    result = []
    for i in xrange(len(items), 0, -1):
        if bestvalue(i, j) != bestvalue(i - 1, j):
            result.append(items[i - 1])
            j -= items[i - 1][1]
    result.reverse()
    return bestvalue(len(items), maxweight), result

def input_str(row):
    res = []
    for _ in range(row):
        res.append(raw_input().split())
    return res

N, W = [int(i) for i in raw_input().split()]
wvlist = input_str(N)
start = time.time()
items = [(int(v), int(w)) for w, v in wvlist]
print knapsack(items, W)[0]
print time.time() - start


### FIXED CODE ###

# -*- coding: utf-8 -*-
def input_str(row):
    res = []
    for _ in range(row):
        res.append(raw_input().split())
    return res

ipt = input_str(2)
N, T = [int(i) for i in ipt[0]]
t = sorted([int(i) for i in ipt[1]])

total = 0
for i, ti in enumerate(t[:-1]):
    if t[i+1] - t[i] > T:
        total += T
    else:
        total += t[i+1] - t[i]

print total + T
def main():
    import sys
    sys.setrecursionlimit(31111)
    import numpy as np
    ikimasu = sys.stdin.buffer.readline
    ini = lambda: int(ins())
    ina = lambda: list(map(int, ikimasu().split()))
    ins = lambda: ikimasu().strip()
    n,k = ina()
    tmp = [[] for _ in range(n)]
    for _ in range(n-1):
        x,x1=  ina()
        x-=1
        x1-=1
        tmp[x].append(x1)
        tmp[x1].append(x)
    def dfs(teiru,ta):
        rick = 1
        coulduse = k-1 if ta==-1 else k-2
        if(coulduse<len(tmp[teiru])):
            return 0
        for i in tmp[teiru]:
            if i == ta:
                continue
            rick*=coulduse
            rick%=1000000007
            coulduse-=1
            rick*=dfs(i,teiru) 
            rick%=1000000007
        return rick
    print(k*dfs(0,-1)%1000000007)
    

    


        
        
        


    
        


        


    




















if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    import sys
    sys.setrecursionlimit(311111)
    import numpy as np
    ikimasu = sys.stdin.buffer.readline
    ini = lambda: int(ins())
    ina = lambda: list(map(int, ikimasu().split()))
    ins = lambda: ikimasu().strip()
    n,k = ina()
    tmp = [[] for _ in range(n)]
    for _ in range(n-1):
        x,x1=  ina()
        x-=1
        x1-=1
        tmp[x].append(x1)
        tmp[x1].append(x)
    def dfs(teiru,ta):
        rick = 1
        coulduse = k-1 if ta==-1 else k-2
        for i in tmp[teiru]:
            if i == ta:
                continue
            rick*=coulduse
            rick%=1000000007
            coulduse-=1
            rick*=dfs(i,teiru) 
            rick%=1000000007
        return rick
    print(k*dfs(0,-1)%1000000007)
    

    


        
        
        


    
        


        


    




















if __name__ == "__main__":
    main()
import sys
input = sys.stdin.readline


def main():
    X, N = map(int, input().split())
    p = list(map(int, input().split()))
    assert N == len(p)
    if N == 0:
        print(X)
        exit()
    abs_list = []
    abs_list2 = list(range(-100, 100))
    abs_list2.sort()
    abs_list2 = sorted(abs_list2, key=abs)
    for i in p:
        abs_list.append(i-X)
    abs_list.sort()
    abs_list = sorted(abs_list, key=abs)
    # print(abs_list)
    # print(abs_list2)
    for i in range(len(abs_list2)):
        if abs_list[i] != abs_list2[i]:
            print(X+abs_list2[i])
            exit()


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline


def main():
    X, N = map(int, input().split())
    p = list(map(int, input().split()))
    assert N == len(p)
    if N == 0:
        print(X)
        exit()
    abs_list = []
    abs_list2 = list(range(-100, 100))
    abs_list2.sort()
    abs_list2 = sorted(abs_list2, key=abs)
    for i in p:
        abs_list.append(i-X)
    abs_list.sort()
    abs_list = sorted(abs_list, key=abs)
    # print(abs_list)
    # print(abs_list2)
    for i in range(N):
        if abs_list[i] != abs_list2[i]:
            print(X+abs_list2[i])
            exit()
    print(X+abs_list2[N])


if __name__ == '__main__':
    main()
s=input()
t=input()
s.sort()
t.sort(reverse=True)
for i in range(min(len(s),len(t))):
  if ord(s[i])==ord(t[i]):
    continue
  elif ord(s[i])<ord(t[i]):
    print("Yes")
    break
  else:
    print("No")
else:
  print("No")

### FIXED CODE ###

s=list(input())
t=list(input())
s.sort()
t.sort(reverse=True)
s="".join(s)
t="".join(t)
for i in range(min(len(s),len(t))):
  if ord(s[i])==ord(t[i]):
    continue
  elif ord(s[i])<ord(t[i]):
    print("Yes")
    break
  else:
    print("No")
    break
else:
  if len(s)<len(t):
    print("Yes")
  else:
    print("No")
import math

a, b, x = map(int, input().split())
if x <= a*a*b/2:
    y = 2*x/(a*b)
    X = math.degrees(math.atan(b/y))
else:
    y = b - x/(a*a)
    X = 90-math.degrees(math.atan(a/2/y))

print(round(X, 10))

### FIXED CODE ###

import math
 
a, b, x = map(int, input().split())
if x == a*a*b:
    p = 0
elif x <= a*a*b/2:
    p = math.degrees(math.atan(b/(2*x/(a*b))))
else:
    p = 90-math.degrees(math.atan(a/2/(b - x/(a*a))))

print(p)
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

from collections import deque
N, M = mi()
x = li2(M)

adj = [[] for i in range(N)]
for i in range(M):
    x[i][0] -= 1
    x[i][1] -= 1
    adj[x[i][0]].append(x[i][1])

flag = [0]*N
ans = deque([])

def dfs(x, ans):
    if flag[x]:
        return None
    else:
        flag[x] = 1
        if adj[x]:
            for a in adj[x]:
                dfs(a, ans)
        #global ans
        ans.appendleft(x)

for i in range(N):
    dfs(i, ans)

#print(ans)

dp = [0]*N
for a in ans:
    if adj[a]:
        for b in adj[a]:
            dp[b] = max(dp[b], dp[a] + 1)

print(max(dp))

### FIXED CODE ###

import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
'''
N, M = mi()
x = li2(M)

#dp = dp2(0, 2, N)
dp = [[0, []] for i1 in range(N+1)]


for i in range(M):
    dp[x[i][1]][0] = max(dp[x[i][1]][0], dp[x[i][0]][0] + 1)
    dp[x[i][0]][1].append(x[i][1])
    if dp[x[i][1]][1] != []:
        for a in dp[x[i][1]][1]:
            dp[a][0] = max(dp[x[i][1]][0] + 1, dp[a][0])

print(dp)
print(max([row[0] for row in dp])) 
'''
from collections import deque
N, M = mi()
x = li2(M)

h = [0]*N
adj = [[] for i in range(N)]
for i in range(M):
    x[i][0] -= 1
    x[i][1] -= 1
    h[x[i][1]] += 1
    adj[x[i][0]].append(x[i][1])

zeros = deque([])
ans = []
for i in range(N):
    if h[i] == 0:
        zeros.append(i)
        ans.append(i)

while(zeros != deque()):
    a = zeros.popleft()
    if(adj[a]):
        for b in adj[a]:
            h[b] -= 1
            if h[b] == 0:
                zeros.append(b)
                ans.append(b)

#print(ans)

dp = [0]*N
#print(ans)
#print(adj)
for a in ans:
    #print(dp)
    if adj[a]:
        for b in adj[a]:
            dp[b] = max(dp[a] + 1, dp[b])
#print(dp)
print(dp[ans[-1]])
n=int(input())
a=list(map(int,input().split()))
q=int(input())
b=[]
c=[]
for _ in range(q):
    x,y=map(int,input().split())
    b.append(x)
    c.append(y)

d=[0]*10000
for i in a:
    d[i]+=1

for m,p in zip(b,c):
    minus=d[m]
    d[m]=0
    d[p]+=minus
    ans=0
    for i in range(len(d)):
        ans+=i*d[i]
    print(ans)


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
q=int(input())
b=[]
c=[]
for _ in range(q):
    x,y=map(int,input().split())
    b.append(x)
    c.append(y)

d=[0]*100001
for i in a:
    d[i]+=1

ans=sum(a)
for m,p in zip(b,c):
    minus=d[m]
    d[m]=0
    d[p]+=minus
    ans+=(p-m)*minus
    print(ans)