Dominoes P73039


Statement
 

pdf   zip

thehtml

Anna and Bernard play the following game: First, they invent five words each. Later, and alternatively, Anna writes her first word, Bernard writes his first word, Anna writes her second word, Bernard writes his second word, and so on. The first to write a word that does not start with the same character with which ends the previous word, loses. (The first word, always Anna’s, can start with any character.) If after writing the 10 words nobody loses, the game ends in a draw.

Write a program to decide who wins every game.

Input

Input begins with a natural number indicating the number of games. Follow the 10 words of every game, in this order: the first word of Anna, the first word of Bernard, the second word of Anna, etcetera.

Output

For each game, print a line with ‘A’, ‘B’, or ‘=’, depending on whether Anna wins, Bernard wins, or it is a tie.

Public test cases
  • Input

    2
    x x x x y x x x x x
    ab bxc cxxd dxxxe exxxxf fxxxxxg gxxxxxxh hxxxxxxxi ixxxxxxxxj jxxxxxxxxxk
    

    Output

    B
    =
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan Spanish
    Official solutions
    C++ Python
    User solutions
    C++ Python