Menu

(Solved) : Code Python S Walking Tour Day Siswinter Tt Groups Students Visiting Torzhok Streets Torzh Q43915644 . . .

This code is in python

It’s a walking tour day in SIS.Winter, so tt groups of studentsare visiting Torzhok. Streets of Torzhok are so narrow thatstudents have to go in a row one after another.

Initially, some students are angry. Let’s describe a group ofstudents 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 firststudent.

Every minute every angry student throws a snowball at the nextstudent. Formally, if an angry student corresponds to the characterwith index ii in the string describing a group then they will throwa snowball at the student that corresponds to the character withindex i+1i+1 (students are given from the last to the firststudent). If the target student was not angry yet, they becomeangry. Even if the first (the rightmost in the string) student isangry, they don’t throw a snowball since there is no one in frontof them.

1f23da2c35f2376e3a2106b44196e6e8b0b2a999

Let’s look at the first example test. The row initially lookslike this: PPAP. Then, after a minute the only single angry studentwill throw a snowball at the student in front of them, and theyalso become angry: PPAA. After that, no more students will becomeangry.

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

Input

The first line contains a single integer tt — the number ofgroups of students (1≤t≤1001≤t≤100). The following 2t2t linescontain descriptions of groups of students.

The description of the group starts with an integer kiki(1≤ki≤1001≤ki≤100) — the number of students in the group, followedby a string sisi, consisting of kiki letters “A” and “P”, whichdescribes the ii-th group of students.

Output

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

Examples

input

14PPAP

output

1

input

312APPAPPPAPPPP3AAP3PPA

output

4inputPoutput0inputAoutput010

Note

In the first test, after 11 minute the state of students becomesPPAA. After that, no new angry students will appear.

In the second tets, state of students in the first group is:

  • after 11 minute — AAPAAPPAAPPP
  • after 22 minutes — AAAAAAPAAAPP
  • after 33 minutes — AAAAAAAAAAAP
  • after 44 minutes all 1212 students are angry

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

Expert Answer


Answer to This code is in python It’s a walking tour day in SIS.Winter, so tt groups of students are visiting Torzhok. Streets of …

OR