It’s a walking tour day in SIS.Winter, so t 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 i in the string describing a group then they will throw a snowball at the student that corresponds to the character with index i+1 (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 t — the number of groups of students (1≤t≤100). The following 2t lines contain descriptions of groups of students.

The description of the group starts with an integer ki (1≤ki≤100) — the number of students in the group, followed by a string si, consisting of ki letters “A” and “P”, which describes the i-th group of students.

Output

For every group output single integer — the last moment a student becomes angry.

Examples

Input

1

4

PPAP

Output

1

Input

3

12

APPAPPPAPPPP

3

AAP

3

PPA

Output

4

1

0

Note

In the first test, after 1 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 1 minute — AAPAAPPAAPPP

after 2 minutes — AAAAAAPAAAPP

after 3 minutes — AAAAAAAAAAAP

after 4 minutes all 12 students are angry

In the second group after 1 minute, all students are angry.

#include <bits/stdc++.h>
using namespace std;
template <typename t>
void read(t &x)
{
char ch = getchar();
x = 0;
t f = 1;
while (ch < '0' || ch > '9')
f = (ch == '-' ? -1 : f), ch = getchar();
while (ch >= '0' && ch <= '9')
x = x * 10 + ch - '0', ch = getchar();
x *= f;
} #define wi(n) printf("%d ", n)
#define wl(n) printf("%lld ", n)
#define rep(m, n, i) for (int i = m; i < n; ++i)
#define rrep(m, n, i) for (int i = m; i > n; --i)
#define P puts(" ")
typedef long long ll;
#define MOD 1000000007
#define mp(a, b) make_pair(a, b)
#define N 10005
#define fil(a, n) rep(0, n, i) read(a[i])
//---------------https://lunatic.blog.csdn.net/-------------------//
string s;
int k,t;
int main()
{
read(t);
while (t--)
{
read(k);
cin >> s;
int count = 0, max = 0, flag = 0;
for (int i = 0; i < k;)
if (s[i] == 'A')
{
count = 0, i++;
while (s[i] == 'P')
count++, i++;
if (count > max)
max = count;
}
else
i++; wi(max);
P;
}
return 0;
}

codeforces 1287A -Angry Students(模拟)的更多相关文章

  1. A. Angry Students

    网址:http://codeforces.com/problemset/problem/1287/A It's a walking tour day in SIS.Winter, so tt grou ...

  2. [模拟]Codeforces Circle of Students

    Circle of Students time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. Codeforces 738D. Sea Battle 模拟

    D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard inp ...

  4. Codeforces 626A Robot Sequence(模拟)

    A. Robot Sequence time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...

  5. CodeForces - 589D(暴力+模拟)

    题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人 ...

  6. Codeforces 767B. The Queue 模拟题

    B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

  7. Codeforces 704A Thor 队列模拟

    题目大意:托尔有一部手机可执行三种操作 1.x APP产生一个新消息 2.读取x App已产生的所有消息 3.读取前t个产生的消息 问每次操作后未读取的消息的数量 题目思路: 队列模拟,坑点在于竟然卡 ...

  8. 【Codeforces 332C】Students' Revenge

    Codeforces 332 C 我爱对拍,对拍使我快乐... 题意:有\(n\)个议题,学生们会让议会同意\(p\)个,其中主席会执行\(k\)个, 每一个议题执行后主席会掉\(a_i\)的头发,不 ...

  9. Vasya And The Mushrooms CodeForces - 1016C (前缀和模拟)

    大意: 给定2*n的矩阵, 每个格子有权值, 走到一个格子的贡献为之前走的步数*权值, 每个格子只能走一次, 求走完所有格子最大贡献. 沙茶模拟打了一个小时总算打出来了 #include <io ...

随机推荐

  1. 微信小程序页面跳转的三种方式总结

    原文链接 https://blog.csdn.net/zgmu/article/details/72123329 首先我们了解到,小程序规定页面路径只能有五层,所以我们尽量避免多层级的页面跳转 页面跳 ...

  2. 在tap的碎片上与活动进行绑定实现点击事件(日期时间选择以及按钮跳转时间)

    主要是掌握怎样在Fragment类型的.java文件中实现对于文本框或者按钮点击事件的触发操作. 相应的出发时间都是之前的代码.主要是怎样在Fragment怎样实现相应的操作主要是对于getActiv ...

  3. [ddt02篇]十年测试老鸟帮您解析:ddt结合txt,excel,csv,mysql实现自动化测试数据驱动

    一.前言: 阅读此文之前请先阅读: [ddt01篇]十年测试老鸟帮您解析:ddt数据驱动入门基础应用:https://www.cnblogs.com/csmashang/p/12679448.html ...

  4. go中的线程的实现模型-P G M的调度

    线程实现模型 go中线程的实现是依靠 P G M M machine的缩写.一个M代表一个内核线程,或称“工作线程” P processor的缩写.一个P代表执行一个Go代码片段所需要的资源(或称“上 ...

  5. D. AB-string

    https://codeforces.com/contest/1238/problem/D 题目大意:统计good string的个数,good string的定义,给定的字符串中含有回文段落, 题解 ...

  6. 详解 Arrays类

    请关注本人博文--<详解 普通数组 -- Arrays类 与 浅克隆> Arrays类: 概述: 针对数组进行操作的工具类.它提供了对于数组的值的排序.查找等功能. 现在,本人来展示一下A ...

  7. shift后门

    shift快捷 Windows的粘滞键------C:\windows\system32\sethc.exe,它本是为不方便按组合键的人设计的 Windows系统按5下shift后,Windows就执 ...

  8. samba 客户端工具 smbclient和samba挂载到本地

    smbclient命令属于samba套件,它提供一种命令行使用交互式方式访问samba服务器的共享资源. 安装 yum install -y samba-client 常用参数 -c<命令> ...

  9. keras API的使用,神经网络层,优化器,损失函数,查看模型层数,compile和fit训练

    layers介绍 Flatten和Dense介绍 优化器 损失函数 compile用法 第二个是onehot编码 模型训练 model.fit  两种创建模型的方法 from tensorflow.p ...

  10. Win7+Linux双系统,完美解决删除Linux后出现的任何问题!

    首先,进入到Win7,安装MiniTool Partition Wizard Home Edition删除掉Linux分区, 点Yes 然后选中 这里选中这个,重写MBR,开机神马grub神马问题都没 ...