codeforces 1287A Angry Students

Angry Students

time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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.ios

Initially, some students are angry. Let’s describe a group of students by a string of capital letters “A” and “P”:web

“A” corresponds to an angry student
“P” corresponds to a patient student
Such string describes the row from the last to the first student.api

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.app

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.svg

Your task is to help SIS.Winter teachers to determine the last moment a student becomes angry for every group.this

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.spa

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.code

Output

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

Examples

input

1
4
PPAPxml

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.

题意:

首先就是有生气的孩子和耐心的孩子,假如生气的孩子的右边是个耐心的孩子,那么他会将雪球扔向右边的孩子,问最后所有生气的孩子没有办法扔雪球用了多久的时间。

思路:

也就是A右边有多少个P,可是由于生气的孩子是同时扔的雪球,因此最后要取最大值,就是最多的时间了。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
template <class T>
inline void read(T &ret) {
    char c;
    int sgn;
    if (c = getchar(), c == EOF) return ;
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    sgn = (c == '-') ? -1:1;
    ret = (c == '-') ? 0:(c - '0');
    while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return ;
}
inline void out(int x) {
    if (x > 9) out(x / 10);
    putchar(x % 10 + '0');
}
int main() {
    int t, n;
    read(t);
    for (int i = 0; i < t; i++) {
        int Max = 0;
        read(n);
        char s[110];
        scanf("%s", s);
        int len = strlen(s);
        for (int i = 0; i < len; i++) {
            if (s[i] == 'A') {
                int j = i + 1;
                while (s[j] == 'P' && j < len) j++;
                j -= 1;
                Max = max(Max, j - i);
                i = j;
            }
        }
        out(Max);
        putchar('\n');
    }
    return 0;
}