401935: GYM100589 C Find P'th Number

Memory Limit:512 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Find P'th Numbertime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard output

Alice had a bag where each number from 1 to N was present in it. After a magic trick she either removes all even numbers or all odd numbers from the bag. Given the kind of trick she has performed find the P’th smallest number in the bag after the trick. For example P  =  1 denotes the smallest number present.

Input

First line contains T, the number of test cases. Each test case consists of N, a string S and an integer P in single line.

S will be either "odd" or "even"(quotes for clarity), denoting the kind of trick Alice has performed.

Note: It is guaranteed that P will be less than or equal to remaining items in the bag.

Output

For each test case print required answer in one line.

Constraints

  • 1T100
  • 1N103
ExamplesInput
2
4 odd 2
5 even 2
Output
4
3
Note

Example 1.

After performing the “odd” trick the numbers 1 and 3 get removed from the bag. Numbers 2 and 4 are left in the bag. 2nd smallest number is 4 now.

Example 2.

After performing the “even” trick the numbers 2 and 4 get removed from the bag. Numbers 1, 3 and 5 are left in the bag. 2nd smallest number is 3 now.

加入题单

上一题 下一题 算法标签: