
from collections import deque
from math import floor
from random import random
from time import time







class 				lowercase		:




							def __init__(				self):
												lowercase							=						{}




							def  A__      (				self   ,A__   ,A__   ,A__=1):
												if self.graph.get(A__):
																	if self.graph[u].count([w, v]) == 0:
																						self.graph[u].append([w, v])
												else:
																	lowercase							=						[[w, v]]
												if not self.graph.get(A__):
																	lowercase							=						[]




							def  A__      (				self):
												return list(self.graph)




							def  A__      (				self   ,A__   ,A__):
												if self.graph.get(A__):
																	for _ in self.graph[u]:
																						if _[1] == v:
																											self.graph[u].remove(A__)




							def  A__      (				self   ,A__=-2   ,A__=-1):
												if s == d:
																	return []
												lowercase							=						[]
												lowercase							=						[]
												if s == -2:
																	lowercase							=						list(self.graph)[0]
												stack.append(A__)
												visited.append(A__)
												lowercase							=						s

												while True:
																	# check if there is any non isolated nodes
																	if len(self.graph[s]) != 0:
																						lowercase							=						s
																						for node in self.graph[s]:
																											if visited.count(node[1]) < 1:
																																if node[1] == d:
																																					visited.append(A__)
																																					return visited
																																else:
																																					stack.append(node[1])
																																					visited.append(node[1])
																																					lowercase							=						node[1]
																																					break

            # check if all the children are visited
																	if s == ss:
																						stack.pop()
																						if len(A__) != 0:
																											lowercase							=						stack[len(A__) - 1]
																	else:
																						lowercase							=						ss

																	# check if se have reached the starting point
																	if len(A__) == 0:
																						return visited




							def  A__      (				self   ,A__=-1):
												if c == -1:
																	lowercase							=						floor(random() * 1_0_0_0_0) + 1_0
												for i in range(A__):
																	# every vertex has max 100 edges
																	for _ in range(floor(random() * 1_0_2) + 1):
																						lowercase							=						floor(random() * c) + 1
																						if n != i:
																											self.add_pair(A__   ,A__   ,1)




							def  A__      (				self   ,A__=-2):
												lowercase							=						deque()
												lowercase							=						[]
												if s == -2:
																	lowercase							=						list(self.graph)[0]
												d.append(A__)
												visited.append(A__)
												while d:
																	lowercase							=						d.popleft()
																	if len(self.graph[s]) != 0:
																						for node in self.graph[s]:
																											if visited.count(node[1]) < 1:
																																d.append(node[1])
																																visited.append(node[1])
												return visited




							def  A__      (				self   ,A__):
												lowercase							=						0
												for x in self.graph:
																	for y in self.graph[x]:
																						if y[1] == u:
																											count += 1
												return count




							def  A__      (				self   ,A__):
												return len(self.graph[u])




							def  A__      (				self   ,A__=-2):
												lowercase							=						[]
												lowercase							=						[]
												if s == -2:
																	lowercase							=						list(self.graph)[0]
												stack.append(A__)
												visited.append(A__)
												lowercase							=						s
												lowercase							=						[]

												while True:
																	# check if there is any non isolated nodes
																	if len(self.graph[s]) != 0:
																						lowercase							=						s
																						for node in self.graph[s]:
																											if visited.count(node[1]) < 1:
																																stack.append(node[1])
																																visited.append(node[1])
																																lowercase							=						node[1]
																																break

            # check if all the children are visited
																	if s == ss:
																						sorted_nodes.append(stack.pop())
																						if len(A__) != 0:
																											lowercase							=						stack[len(A__) - 1]
																	else:
																						lowercase							=						ss

																	# check if se have reached the starting point
																	if len(A__) == 0:
																						return sorted_nodes




							def  A__      (				self):
												lowercase							=						[]
												lowercase							=						[]
												lowercase							=						list(self.graph)[0]
												stack.append(A__)
												visited.append(A__)
												lowercase							=						-2
												lowercase							=						[]
												lowercase							=						s
												lowercase							=						False
												lowercase							=						set()

												while True:
																	# check if there is any non isolated nodes
																	if len(self.graph[s]) != 0:
																						lowercase							=						s
																						for node in self.graph[s]:
																											if (
																											    visited.count(node[1]) > 0
																											    and node[1] != parent
																											    and indirect_parents.count(node[1]) > 0
																											    and not on_the_way_back
																											):
																																lowercase							=						len(A__) - 1
																																while len_stack >= 0:
																																					if stack[len_stack] == node[1]:
																																										anticipating_nodes.add(node[1])
																																										break
																																					else:
																																										anticipating_nodes.add(stack[len_stack])
																																										len_stack -= 1
																											if visited.count(node[1]) < 1:
																																stack.append(node[1])
																																visited.append(node[1])
																																lowercase							=						node[1]
																																break

            # check if all the children are visited
																	if s == ss:
																						stack.pop()
																						lowercase							=						True
																						if len(A__) != 0:
																											lowercase							=						stack[len(A__) - 1]
																	else:
																						lowercase							=						False
																						indirect_parents.append(A__)
																						lowercase							=						s
																						lowercase							=						ss

																	# check if se have reached the starting point
																	if len(A__) == 0:
																						return list(A__)




							def  A__      (				self):
												lowercase							=						[]
												lowercase							=						[]
												lowercase							=						list(self.graph)[0]
												stack.append(A__)
												visited.append(A__)
												lowercase							=						-2
												lowercase							=						[]
												lowercase							=						s
												lowercase							=						False
												lowercase							=						set()

												while True:
																	# check if there is any non isolated nodes
																	if len(self.graph[s]) != 0:
																						lowercase							=						s
																						for node in self.graph[s]:
																											if (
																											    visited.count(node[1]) > 0
																											    and node[1] != parent
																											    and indirect_parents.count(node[1]) > 0
																											    and not on_the_way_back
																											):
																																lowercase							=						len(A__) - 1
																																while len_stack_minus_one >= 0:
																																					if stack[len_stack_minus_one] == node[1]:
																																										anticipating_nodes.add(node[1])
																																										break
																																					else:
																																										return True
																											if visited.count(node[1]) < 1:
																																stack.append(node[1])
																																visited.append(node[1])
																																lowercase							=						node[1]
																																break

            # check if all the children are visited
																	if s == ss:
																						stack.pop()
																						lowercase							=						True
																						if len(A__) != 0:
																											lowercase							=						stack[len(A__) - 1]
																	else:
																						lowercase							=						False
																						indirect_parents.append(A__)
																						lowercase							=						s
																						lowercase							=						ss

																	# check if se have reached the starting point
																	if len(A__) == 0:
																						return False




							def  A__      (				self   ,A__=-2   ,A__=-1):
												lowercase							=						time()
												self.dfs(A__   ,A__)
												lowercase							=						time()
												return end - begin





							def  A__      (				self   ,A__=-2):
												lowercase							=						time()
												self.bfs(A__)
												lowercase							=						time()
												return end - begin







class 				lowercase		:




							def __init__(				self):
												lowercase							=						{}




							def  A__      (				self   ,A__   ,A__   ,A__=1):
												# check if the u exists
												if self.graph.get(A__):
																	# if there already is a edge
																	if self.graph[u].count([w, v]) == 0:
																						self.graph[u].append([w, v])
												else:
																	# if u does not exist
																	lowercase							=						[[w, v]]
												# add the other way
												if self.graph.get(A__):
																	# if there already is a edge
																	if self.graph[v].count([w, u]) == 0:
																						self.graph[v].append([w, u])
												else:
																	# if u does not exist
																	lowercase							=						[[w, u]]




							def  A__      (				self   ,A__   ,A__):
												if self.graph.get(A__):
																	for _ in self.graph[u]:
																						if _[1] == v:
																											self.graph[u].remove(A__)
        # the other way round
												if self.graph.get(A__):
																	for _ in self.graph[v]:
																						if _[1] == u:
																											self.graph[v].remove(A__)




							def  A__      (				self   ,A__=-2   ,A__=-1):
												if s == d:
																	return []
												lowercase							=						[]
												lowercase							=						[]
												if s == -2:
																	lowercase							=						list(self.graph)[0]
												stack.append(A__)
												visited.append(A__)
												lowercase							=						s

												while True:
																	# check if there is any non isolated nodes
																	if len(self.graph[s]) != 0:
																						lowercase							=						s
																						for node in self.graph[s]:
																											if visited.count(node[1]) < 1:
																																if node[1] == d:
																																					visited.append(A__)
																																					return visited
																																else:
																																					stack.append(node[1])
																																					visited.append(node[1])
																																					lowercase							=						node[1]
																																					break

            # check if all the children are visited
																	if s == ss:
																						stack.pop()
																						if len(A__) != 0:
																											lowercase							=						stack[len(A__) - 1]
																	else:
																						lowercase							=						ss

																	# check if se have reached the starting point
																	if len(A__) == 0:
																						return visited




							def  A__      (				self   ,A__=-1):
												if c == -1:
																	lowercase							=						floor(random() * 1_0_0_0_0) + 1_0
												for i in range(A__):
																	# every vertex has max 100 edges
																	for _ in range(floor(random() * 1_0_2) + 1):
																						lowercase							=						floor(random() * c) + 1
																						if n != i:
																											self.add_pair(A__   ,A__   ,1)




							def  A__      (				self   ,A__=-2):
												lowercase							=						deque()
												lowercase							=						[]
												if s == -2:
																	lowercase							=						list(self.graph)[0]
												d.append(A__)
												visited.append(A__)
												while d:
																	lowercase							=						d.popleft()
																	if len(self.graph[s]) != 0:
																						for node in self.graph[s]:
																											if visited.count(node[1]) < 1:
																																d.append(node[1])
																																visited.append(node[1])
												return visited




							def  A__      (				self   ,A__):
												return len(self.graph[u])




							def  A__      (				self):
												lowercase							=						[]
												lowercase							=						[]
												lowercase							=						list(self.graph)[0]
												stack.append(A__)
												visited.append(A__)
												lowercase							=						-2
												lowercase							=						[]
												lowercase							=						s
												lowercase							=						False
												lowercase							=						set()

												while True:
																	# check if there is any non isolated nodes
																	if len(self.graph[s]) != 0:
																						lowercase							=						s
																						for node in self.graph[s]:
																											if (
																											    visited.count(node[1]) > 0
																											    and node[1] != parent
																											    and indirect_parents.count(node[1]) > 0
																											    and not on_the_way_back
																											):
																																lowercase							=						len(A__) - 1
																																while len_stack >= 0:
																																					if stack[len_stack] == node[1]:
																																										anticipating_nodes.add(node[1])
																																										break
																																					else:
																																										anticipating_nodes.add(stack[len_stack])
																																										len_stack -= 1
																											if visited.count(node[1]) < 1:
																																stack.append(node[1])
																																visited.append(node[1])
																																lowercase							=						node[1]
																																break

            # check if all the children are visited
																	if s == ss:
																						stack.pop()
																						lowercase							=						True
																						if len(A__) != 0:
																											lowercase							=						stack[len(A__) - 1]
																	else:
																						lowercase							=						False
																						indirect_parents.append(A__)
																						lowercase							=						s
																						lowercase							=						ss

																	# check if se have reached the starting point
																	if len(A__) == 0:
																						return list(A__)




							def  A__      (				self):
												lowercase							=						[]
												lowercase							=						[]
												lowercase							=						list(self.graph)[0]
												stack.append(A__)
												visited.append(A__)
												lowercase							=						-2
												lowercase							=						[]
												lowercase							=						s
												lowercase							=						False
												lowercase							=						set()

												while True:
																	# check if there is any non isolated nodes
																	if len(self.graph[s]) != 0:
																						lowercase							=						s
																						for node in self.graph[s]:
																											if (
																											    visited.count(node[1]) > 0
																											    and node[1] != parent
																											    and indirect_parents.count(node[1]) > 0
																											    and not on_the_way_back
																											):
																																lowercase							=						len(A__) - 1
																																while len_stack_minus_one >= 0:
																																					if stack[len_stack_minus_one] == node[1]:
																																										anticipating_nodes.add(node[1])
																																										break
																																					else:
																																										return True
																											if visited.count(node[1]) < 1:
																																stack.append(node[1])
																																visited.append(node[1])
																																lowercase							=						node[1]
																																break

            # check if all the children are visited
																	if s == ss:
																						stack.pop()
																						lowercase							=						True
																						if len(A__) != 0:
																											lowercase							=						stack[len(A__) - 1]
																	else:
																						lowercase							=						False
																						indirect_parents.append(A__)
																						lowercase							=						s
																						lowercase							=						ss

																	# check if se have reached the starting point
																	if len(A__) == 0:
																						return False




							def  A__      (				self):
												return list(self.graph)




							def  A__      (				self   ,A__=-2   ,A__=-1):
												lowercase							=						time()
												self.dfs(A__   ,A__)
												lowercase							=						time()
												return end - begin





							def  A__      (				self   ,A__=-2):
												lowercase							=						time()
												self.bfs(A__)
												lowercase							=						time()
												return end - begin






from functools import lru_cache



@lru_cache
def        UpperCamelCase    (							lowerCAmelCase__		):
					'''simple docstring'''
					if num < 0:
										raise ValueError('''Number should not be negative.'''		)

					return 1 if num in (0, 1) else num * factorial(num - 1		)


if __name__ == "__main__":
							import doctest

							doctest.testmod()




