시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 9 4 4 66.667%

문제

31게임은 옛날 옛날에 기차를 타고 다니던 사기꾼들이 제일 좋아했던 게임이다. 이 게임은 24개의 카드로 이루어진 카드팩을 이용한다. 1,2,3,4,5,6이 쓰여진 카드가 4개씩 있다. 카드팩의 카드는 두명의 플레이어 모두가 볼 수 있다. 두명의 플레이어는 번갈아 가면서 카드팩에서 카드를 한장씩 가져온다. 그리고 카드를 같은 곳에 쌓아놓는다.

게임의 목표는 마지막 플레이어가 카드를 쌓았을 때 쌓여 있는 카드의 합이 31을 초과하지 않아야 한다는 것이다. 

상윤이는 두명의 플레이어가 선택한 카드의 순서가 주어졌을 때 최종적으로 우승하는 플레이어가 누구인지 결정하는 프로그램을 작성하려고 한다.

두 플레이어는 나머지 카드 중 자신이 이기기 위한 완벽한 전략을 사용한다고 가정한다.

예를 들어 플레이어 찬미와 아람이가 다음과 같은 순서로 카드를 뽑는다고 가정한다.

  • 찬미 3
  • 아람 5
  • 찬미 6
  • 아람 6
  • 찬미 5
  • 아람 6

이렇게 쌓아올리면 쌓여진 총 카드의 숫자들의 합은 31이 된다 다음 차례인 찬미가 무슨 카드를 뽑던지 31을 초과하여 찬미가 지고 아람이가 이기게 된다.

상윤이가 프로그램을 짤 수 있게 도와주자

입력

몇개의 줄에 걸쳐 입력이 주어진다. 여러개의 비트로 입력이 들어온다. 첫 번째 비트는 플레이어 A가 선택하는 카드의 수이고 두 번째 비트는 플레이어 B가 선택하는 수이다. 이 순서로 비트가 반복해서 들어온다.

완벽한 전략으로 게임을 이어나갔을 때 두명의 플레이어 중 누가 이기는지를 결정해야 한다.

출력

각 게임별로 입력으로 주어진 값과 게임의 최종 승자를 공백을 사이에 두고 출력하여라.

예제 입력 1

356656
35665
3566
111126666
552525

예제 출력 1

356656 B
35665 B
3566 A
111126666 A
552525 A
W3sicHJvYmxlbV9pZCI6IjQxNDgiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0b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