output_description: Print a string that represents the state of each device after K balls are
  processed. The string must be N characters long, and the i-th character must
  correspond to the state of the i-th device from the left.
  
  * * *
input_description: The input is given from Standard Input in the following format:
  
      
      
      N K
      S
attempt: import sys
  
  read = sys.stdin.buffer.read
  readline = sys.stdin.buffer.readline
  readlines = sys.stdin.buffer.readlines
  sys.setrecursionlimit(10**7)
  
  from collections import deque
  
  # f(AX) = XB
  # f(BX) = flip(X) + A = flip(XB)
  
  N, K = map(int, readline().split())
  S = read().rstrip()
  S = deque(0 if x == b"A"[0] else 1 for x in S)
  
  # Kが大きいときは、周期で減らせる
  if K > 20100 + 100:
      K = 20100 + (K & 1)
  
  flip = 0
  for _ in range(K):
      top = S[0] ^ flip
      if top == 0:
          # A
          S[0] ^= 1
      else:
          # B
          flip ^= 1
          S.popleft()
          S.append(flip)
  
  if flip == 0:
      A = "A"
      B = "B"
  else:
      A = "B"
      B = "A"
  answer = "".join(A if x == 0 else B for x in S)
  print(answer)
  
problem_description: Statement
  
  Takahashi has a lot of peculiar devices. These cylindrical devices receive
  balls from left and right. Each device is in one of the two states A and B,
  and for each state, the device operates as follows:
  
    * When a device in state A receives a ball from either side (left or right), the device throws out the ball from the same side, then immediately goes into state B.
    * When a device in state B receives a ball from either side, the device throws out the ball from the other side, then immediately goes into state A.
  
  The transition of the state of a device happens momentarily and always
  completes before it receives another ball.
  
  Takahashi built a contraption by concatenating N of these devices. In this
  contraption,
  
    * A ball that was thrown out from the right side of the i-th device from the left (1 \leq i \leq N-1) immediately enters the (i+1)-th device from the left side.
    * A ball that was thrown out from the left side of the i-th device from the left (2 \leq i \leq N) immediately enters the (i-1)-th device from the right side.
  
  The initial state of the i-th device from the left is represented by the i-th
  character in a string S. From this situation, Takahashi performed the
  following K times: put a ball into the leftmost device from the left side,
  then wait until the ball comes out of the contraption from either end. Here,
  it can be proved that the ball always comes out of the contraption after a
  finite time. Find the state of each device after K balls are processed.
samples: [{"input": "5 1\n    ABAAA", "output": "BBAAA\n    \n\nIn this input, we put a ball into the leftmost device from the left side, then\nit is returned from the same place.\n\n* * *"}, {"input": "5 2\n    ABAAA", "output": "ABBBA\n    \n\n* * *"}, {"input": "4 123456789\n    AABB", "output": "BABA"}]