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. docker win10 基本指令

    一.镜像操作 docker images 本地镜像 docker pull imagename 获取网上获取镜像 docker run 创建docker容器 docker rmi imagename ...

  2. 分治算法(C++版)

    #include<iostream>using namespace std;  void printArray(int array[],int length)  {      for (i ...

  3. 基于 Jepsen 来发现几个 Raft 实现中的一致性问题(2)

    Nebula Graph 是一个高性能.高可用.强一致的分布式图数据库.由于 Nebula Graph 采用的是存储计算分离架构,在存储层实际只是暴露了简单的 kv 接口,采用 RocksDB 作为状 ...

  4. Linux下删除大量文件效率对比

    来自公众号:马哥Linux运维 今天我们来测试一下Linux下面删除大量文件的效率. 首先建立50万个文件 $ test   for i in $(seq 1 500000);do echo text ...

  5. Java基础】并发 - 多线程

    Java基础]并发 - 多线程 分类: Java2014-05-03 23:56 275人阅读 评论(0) 收藏 举报 Java   目录(?)[+]   介绍 Java多线程 多线程任务执行 大多数 ...

  6. Android传感器--光照传感器使用

    Android 设备中有许多传感器,其中有一个传感器控制着你屏幕亮度的变化.当你在很暗的地方使用手机,你设备的屏幕会自动调暗,从而保护你眼睛. 起着这样作用,Android是通过一款光照传感器来获取你 ...

  7. 使用malloc和free函数进行内存动态分配

    一.在学习c语言里面,内存分配这个话题非常有意思,因为我们平时在开发的时候,如果一不小心没注意内存释放的话,写的的程序很容易出错,所以今天就来回顾一下c语言里面的内存动态分配,下面我们先来看一个实例来 ...

  8. python2.7安装pip

  9. Docker-None & Host 网络

    本节介绍None&Host网络. 1.前言 点击此处回到docker系列文章目录 前面我们介绍了bridge network,本小节继续介绍none和host.这两个比较简单,也不太常用.安装 ...

  10. OkHttp 优雅封装 HttpUtils 之 上传下载解密

    曾经在代码里放荡不羁,如今在博文中日夜兼行,只为今天与你分享成果.如果觉得本文有用,记得关注我,我将带给你更多. 还没看过第一篇文章的欢迎移步:OkHttp 优雅封装 HttpUtils 之气海雪山初 ...