{"trustable":true,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003eSometimes, technical terms implicate some life philosophy. Mutex is one of them. On your way to dream, you may be locked by some difficulties, and you need someone to stop his step, and help you get through them.\u003cbr\u003e\u003cbr\u003eTo help you know better about the life philosophy inside mutex, Rikka comes up with a simple task. Maybe some of you know little about mutex, so she uses another scene to replace it.\u003cbr\u003e\u003cbr\u003eThere are $n$ gates in a row, several people in the left side of the gates and all of them want to go to the right side. There are two kinds of gates: black and white. These people share energy, which is represented by a non-negative number $E$. Initially, $E \u003d0 $.\u003cbr\u003e\u003cbr\u003eIf one person walks through a white gate, he will gain one point of energy, i.e., $E$ will be added by $1$. And if one person walks through a black gate, he will lose one point of energy, i.e., $E$ will be subtracted by $1$. Since $E$ must be a non-negative integer, if $E\u003d0$, no one can walk through a black gate until someone walks through a white gate. You can assume there won\u0027t be two people moving at the same time and all the people are selfless.\u003cbr\u003e\u003cbr\u003eWe use P to represent a black gate, V to represent a white gate and use a PV string to represent the row. Initially, all the people are at the beginning of the string, and all of them want to go through the whole string. But unfortunately, sometimes it may be impossible. So, they want to send at least one person to the right side. \u003cbr\u003e\u003cbr\u003eYour task is to find out the minimal number of people which this group needs to achieve this goal.\u003cbr\u003e\u003cbr\u003eFor example, if the row is VPP, they need at least two people: The first person walk through the first white gate and the second person can use this point of energy to go through the whole string.\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The first line contains a single numner $t(1 \\leq t \\leq 10^3)$, the number of the testcases.\u003cbr\u003e\u003cbr\u003eFor each testcase, the first line contains a PV string $s(1 \\leq |s| \\leq 10^5)$ describing the gates.\u003cbr\u003e\u003cbr\u003eThe input guarantees that there are at most $30$ testcases with $|S| \u0026gt; 1000$."}},{"title":"Output","value":{"format":"HTML","content":"For each testcase, output a single integer, the answer. And if it is impossible, output $-1$.\u003cbr\u003e\u003cbr\u003e"}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e4\r\nVPP\r\nVPPVVVVPPPPPPPP\r\nVPPPPPPPPPPPPPP\r\nP\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e2\r\n3\r\n14\r\n-1\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}