



from collections import deque

def   SCREAMING_SNAKE_CASE_       (  _snake_case  :List[Any]							)     ->    Union[str, Any]:
   return input(_snake_case							).strip().split(''' '''							)

def   SCREAMING_SNAKE_CASE_       (  _snake_case  :int  ,      _snake_case  :int							)     ->    dict[int, list[int]]:
   _A						     =					{}
   for i in range(_snake_case							):
      _A						     =					[]

   for e in range(_snake_case							):
      _A     ,						_A						     =					(int(_snake_case							) for i in _input(F'''Edge {e + 1}: <node1> <node2> '''							))
      graph[x].append(_snake_case							)
   return graph

def   SCREAMING_SNAKE_CASE_       (  _snake_case  :int  ,      _snake_case  :int							)     ->    dict[int, list[int]]:
   _A						     =					{}
   for i in range(_snake_case							):
      _A						     =					[]

   for e in range(_snake_case							):
      _A     ,						_A						     =					(int(_snake_case							) for i in _input(F'''Edge {e + 1}: <node1> <node2> '''							))
      graph[x].append(_snake_case							)
      graph[y].append(_snake_case							)
   return graph

def   SCREAMING_SNAKE_CASE_       (  _snake_case  :int  ,      _snake_case  :int							)     ->    dict[int, list[tuple[int, int]]]:
   _A						     =					{}
   for i in range(_snake_case							):
      _A						     =					[]

   for e in range(_snake_case							):
      _A     ,						_A     ,						_A						     =					(int(_snake_case							) for i in _input(F'''Edge {e + 1}: <node1> <node2> <weight> '''							))
      graph[x].append((y, w)							)
      graph[y].append((x, w)							)
   return graph


if __name__ == "__main__":
   UpperCAmelCase_   ,UpperCAmelCase_		   =				(int(i) for i in _input("""Number of nodes and edges: """))

   UpperCAmelCase_		   =				int(
       _input(
           """Press 1 or 2 or 3 \n"""
           """1. Unweighted directed \n"""
           """2. Unweighted undirected \n"""
           """3. Weighted undirected \n"""
       )[0]
   )

   UpperCAmelCase_		   =				{
       1: initialize_unweighted_directed_graph,
       2: initialize_unweighted_undirected_graph,
       3: initialize_weighted_undirected_graph,
   }[graph_choice](n, m)

def   SCREAMING_SNAKE_CASE_       (  _snake_case  :str  ,      _snake_case  :Optional[Any]							)     ->    Tuple:
   _A     ,						_A						     =					{s}, [s]
   print(_snake_case							)
   while _s:
      _A						     =					0
      for i in g[_s[-1]]:
         if i not in vis:
            _s.append(_snake_case							)
            vis.add(_snake_case							)
            _A						     =					1
            print(_snake_case							)
            break
      if not flag:
         _s.pop()

def   SCREAMING_SNAKE_CASE_       (  _snake_case  :Dict  ,      _snake_case  :Optional[int]							)     ->    Dict:
   _A     ,						_A						     =					{s}, deque([s]							)
   print(_snake_case							)
   while q:
      _A						     =					q.popleft()
      for v in g[u]:
         if v not in vis:
            vis.add(_snake_case							)
            q.append(_snake_case							)
            print(_snake_case							)

def   SCREAMING_SNAKE_CASE_       (  _snake_case  :Any  ,      _snake_case  :Union[str, Any]							)     ->    Union[str, Any]:
   _A     ,						_A     ,						_A						     =					{s: 0}, set(), {s: 0}
   while True:
      if len(_snake_case							) == len(_snake_case							) - 1:
         break
      _A						     =					100_000
      for i in dist:
         if i not in known and dist[i] < mini:
            _A						     =					dist[i]
            _A						     =					i
      known.add(_snake_case							)
      for v in g[u]:
         if v[0] not in known and dist[u] + v[1] < dist.get(v[0]  ,      100_000							):
            _A						     =					dist[u] + v[1]
            _A						     =					u
   for i in dist:
      if i != s:
         print(dist[i]							)

def   SCREAMING_SNAKE_CASE_       (  _snake_case  :Optional[int]  ,      _snake_case  :Union[str, Any]=None  ,      _snake_case  :Union[str, Any]=None							)     ->    str:
   if q is None:
      _A						     =					[1]
   if ind is None:
      _A						     =					[0] * (len(_snake_case							) + 1)  # SInce oth Index is ignored
      for u in g:
         for v in g[u]:
            ind[v] += 1
      _A						     =					deque()
      for i in g:
         if ind[i] == 0:
            q.append(_snake_case							)
   if len(_snake_case							) == 0:
      return
   _A						     =					q.popleft()
   print(_snake_case							)
   for w in g[v]:
      ind[w] -= 1
      if ind[w] == 0:
         q.append(_snake_case							)
   topo(_snake_case  ,      _snake_case  ,      _snake_case							)

def   SCREAMING_SNAKE_CASE_       (  )     ->    str:
   _A						     =					input().strip()
   _A						     =					[]
   for _ in range(_snake_case							):
      a.append(map(_snake_case  ,      input().strip().split()							)							)
   return a, n

def   SCREAMING_SNAKE_CASE_       (  _snake_case  :Any							)     ->    Dict:
   ((_A)     ,						(_A))						     =					a_and_n
   _A						     =					list(_snake_case							)
   _A						     =					[[0] * n for i in range(_snake_case							)]
   for k in range(_snake_case							):
      for i in range(_snake_case							):
         for j in range(_snake_case							):
            if dist[i][j] > dist[i][k] + dist[k][j]:
               _A						     =					dist[i][k] + dist[k][j]
               _A						     =					k
   print(_snake_case							)

def   SCREAMING_SNAKE_CASE_       (  _snake_case  :List[Any]  ,      _snake_case  :str							)     ->    Union[str, Any]:
   _A     ,						_A     ,						_A						     =					{s: 0}, set(), {s: 0}
   while True:
      if len(_snake_case							) == len(_snake_case							) - 1:
         break
      _A						     =					100_000
      for i in dist:
         if i not in known and dist[i] < mini:
            _A						     =					dist[i]
            _A						     =					i
      known.add(_snake_case							)
      for v in g[u]:
         if v[0] not in known and v[1] < dist.get(v[0]  ,      100_000							):
            _A						     =					v[1]
            _A						     =					u
   return dist

def   SCREAMING_SNAKE_CASE_       (  )     ->    Dict:
   _A     ,						_A						     =					map(_snake_case  ,      input().split(''' '''							)							)
   _A						     =					[]
   for _ in range(_snake_case							):
      edges.append(map(_snake_case  ,      input().split(''' '''							)							)							)
   return edges, n

def   SCREAMING_SNAKE_CASE_       (  _snake_case  :Tuple							)     ->    List[Any]:
   # Sort edges on the basis of distance
   ((_A)     ,						(_A))						     =					e_and_n
   e.sort(reverse=_snake_case  ,      key=lambda _snake_case							: x[2]							)
   _A						     =					[{i} for i in range(1  ,      n + 1							)]
   while True:
      if len(_snake_case							) == 1:
         break
      print(_snake_case							)
      _A						     =					e.pop()
      for i in range(len(_snake_case							)							):
         if x[0] in s[i]:
            break
      for j in range(len(_snake_case							)							):
         if x[1] in s[j]:
            if i == j:
               break
            s[j].update(s[i]							)
            s.pop(_snake_case							)
            break


def   SCREAMING_SNAKE_CASE_       (  _snake_case  :List[Any]							)     ->    List[Any]:
   _A						     =					[]
   for node in graph:
      if not graph[node]:
         isolated.append(_snake_case							)
   return isolated








from __future__ import annotations

def   SCREAMING_SNAKE_CASE_       (  _snake_case  :int							)     ->    int | None:
   for r in range(1  ,      _snake_case							):
      _A						     =					[]
      for x in range(n - 1							):
         _A						     =					pow(_snake_case  ,      _snake_case  ,      _snake_case							)
         if val in li:
            break
         li.append(_snake_case							)
      else:
         return r
   return None


if __name__ == "__main__":
   UpperCAmelCase_		   =				int(input("""Enter a prime number q: """))
   UpperCAmelCase_		   =				find_primitive(q)
   if a is None:
      print(f'Cannot find the primitive for the value: {a!r}')
   else:
      UpperCAmelCase_		   =				int(input("""Enter private key of A: """))
      UpperCAmelCase_		   =				pow(a, a_private, q)
      UpperCAmelCase_		   =				int(input("""Enter private key of B: """))
      UpperCAmelCase_		   =				pow(a, b_private, q)

      UpperCAmelCase_		   =				pow(b_public, a_private, q)
      UpperCAmelCase_		   =				pow(a_public, b_private, q)

      print("""The key value generated by A is: """, a_secret)
      print("""The key value generated by B is: """, b_secret)



