欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1287A.Angry Students
Angry Students
It's a walking tour day in SIS.Winter, so groups of students are visiting Torzhok. Streets of Torzhok are so narrow that students have to go in a row one after another.
Initially, some students are angry. Let's describe a group of students by a string of capital letters "A" and "P":
- "
A" corresponds to an angry student - "
P" corresponds to a patient student
Such string describes the row from the last to the first student.
Every minute every angry student throws a snowball at the next student. Formally, if an angry student corresponds to the character with index in the string describing a group then they will throw a snowball at the student that corresponds to the character with index (students are given from the last to the first student). If the target student was not angry yet, they become angry. Even if the first (the rightmost in the string) student is angry, they don't throw a snowball since there is no one in front of them.

Let's look at the first example test. The row initially looks like this: PPAP. Then, after a minute the only single angry student will throw a snowball at the student in front of them, and they also become angry: PPAA. After that, no more students will become angry.
Your task is to help SIS.Winter teachers to determine the last moment a student becomes angry for every group.
Input
The first line contains a single integer — the number of groups of students (). The following lines contain descriptions of groups of students.
The description of the group starts with an integer () — the number of students in the group, followed by a string , consisting of letters "A" and "P", which describes the -th group of students.
Output
For every group output single integer — the last moment a student becomes angry.
Note
In the first test, after minute the state of students becomes PPAA. After that, no new angry students will appear.
In the second tets, state of students in the first group is:
- after minute —
AAPAAPPAAPPP - after minutes —
AAAAAAPAAAPP - after minutes —
AAAAAAAAAAAP - after minutes all students are angry
In the second group after minute, all students are angry.
Samples
1
4
PPAP
1
3
12
APPAPPPAPPPP
3
AAP
3
PPA
4
1
0
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |