8667: Painting Game

内存限制:128 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

There is a paper strip divided into nn blank grids. For each i(1i<n), grid i and i+1 are considered adjacent.

Alice and Bob are going to play a game on the strip. They take turns to make move. In one move the player must paint one of the remaining blank grids black, while keeping the rule that no two black grids are adjacent.

The game ends when one of the players is unable to paint any grid, and the score of the game is defined as the total number of grids painted black. Alice wants to minimize the score, while Bob wants to maximize it.

Given n and the side starting the game, find out the final score when both players play optimally.

输入格式

The first line contains an integer T(1T105) - the number of test cases.

The first line of each test case contains an integer n(1n109) and a string s(sAlice,Bob) - the number of grids and the starting player of this game.

输出格式

For each test case, output the final score when both players play optimally in a single line.

输入样例 复制

4
3 Alice
3 Bob
19 Alice
23 Bob

输出样例 复制

1
2
8
10