Many old chess books use descriptive notation to notate squares on a chessboard, naming the file (column) of the square based on the starting piece positions of White or Black, depending on whose move it is. The ranks (rows) are numbered 1 through 8, with 1 being closest to the player. For example, from White's perspective, QR2 represents the file where the queenside rook started, on the 2nd rank from the bottom.
However, this system has been entirely replaced by algebraic notation in the past few decades, which simply notates files with letters a-h and rows with numbers 1-8, always "from White's point of view". Therefore it would be convenient to have a program that can translate squares from old books.
Note: This problem is the simplified inverse of Convert Algebraic notation to Descriptive notation
Credit: David Eppstein
Credit: ILA-boy, Klin, Beao
Given a chess square as a string and either white or black's perspective in descriptive notation, output the chess square in algebraic notation. Reasonable inputs may be used, such as a boolean for white/black perspective. For simplicity, we do not handle moves (including captures) or special symbols (promotion, castling, blunders, end of game, etc.)
The inputs and outputs are case sensitive and follow the above diagrams, with descriptive notation always using capital letters and algebraic notation always using lowercase letters. You must take the input square as one string like "QR1", not two like "QR" and "1".
white,QR1 => a1 white,KR8 => h8 white,Q4 => d4 white,KN7 => g7 black,QR1 => a8 black,KR8 => h1 black,Q4 => d5 black,KN7 => g2