欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1428C.ABBB
ABBB
Zookeeper is playing a game. In this game, Zookeeper must use bombs to bomb a string that consists of letters 'A' and 'B'. He can use bombs to bomb a substring which is either "AB" or "BB". When he bombs such a substring, the substring gets deleted from the string and the remaining parts of the string get concatenated.
For example, Zookeeper can use two such operations: AAB``AB``BA AA``BB``A AAA.
Zookeeper wonders what the shortest string he can make is. Can you help him find the length of the shortest string?
Input
Each test contains multiple test cases. The first line contains a single integer — the number of test cases. The description of the test cases follows.
Each of the next lines contains a single test case each, consisting of a non-empty string : the string that Zookeeper needs to bomb. It is guaranteed that all symbols of are either 'A' or 'B'.
It is guaranteed that the sum of (length of ) among all test cases does not exceed .
Output
For each test case, print a single integer: the length of the shortest string that Zookeeper can make.
Note
For the first test case, you can't make any moves, so the answer is .
For the second test case, one optimal sequence of moves is B``AB``A BA. So, the answer is .
For the third test case, one optimal sequence of moves is AABBBABBBB AABBBABB AABBBB ABBB AB (empty string). So, the answer is .
Samples
3
AAA
BABA
AABBBABBBB
3
2
0
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |