UVa 278 Chess (Idea question)

Source: Internet
Author: User

278-chess

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php? Option=com_onlinejudge&itemid=8&category=467&page=show_problem&problem=21 4

Almost everyone knows the problem of putting eight queens on a chessboard such that no Queen can take another Q Ueen. Timman (a famous Dutch chessplayer) wants to know the maximum number of chesspieces of one kind which can is put on board with a certain size such that no piece can take another. Because it ' s rather difficult to find a solution by hand, and he asks your help to solve the problem.

He doesn ' t need to know the answer for every piece. Pawns seems rather uninteresting and he doesn ' t like bishops anyway. He is wants to know how many Rooks, Knights, Queens or Kings can is placed on one board, such that one piece can ' t take any other.

Input

The "a" of input contains the number of problems. A problem is stated in one line and consists of one character from the following set R, K, Q, C3>k, meaning respectively the chesspieces Rook, Knight, Queen or King. The character is followed by the integers m ( ) and n ( ), meaning the number of row S and the number of columns or the board.

Output

For each problem specification in the input your program should output the maximum number of chesspieces which can is put On a board with the "given formats so they are does not be in position to take all other piece.

Note: The bottom left square is 1, 1.

Sample Input

2
R 6 7
K 8 8

Sample Output

6
32

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.