Chocolate is Tasty

아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

A mother wishes to share a chocolate bar among her children. A child can be either a boy or a girl. The children sit in a circle and consecutively take a line of chocolate in clockwise order. At the beginning, the chocolate bar has nn rows and mm columns. Each boy is greedy and takes one line from the longer side of the chocolate bar. Each girl wishes to keep fit so she takes one line from the shorter side. Mother has to choose from which child she should start to maximize the number of kids that will share the chocolate.

입력

The first line of input consists of zz, the number of test cases. The description of the test cases follows.

Each line consists of two integers nn and mm separated by a space (1n,m1061 \leq n, m \leq 10^6). They are followed by a space and a sequence of letters "B" and "G" which identify the children on the circle in clockwise order. The length of the sequence is not greater than 10610^6.

출력

For each test case, print a line with single a interger: the maximal number of children that can eat a chocolate. Do not count the same kid twice even if he/she receive the chocolate twice.