PAREN - COUNT PAREN

You are given a boolean expression consisting of a string of the symbols 'true', 'false', 'and', 'or', and 'xor'. Count the number of ways to parenthesize the expression such that it will evaluate to true.

"and", "or" and "xor" are of the same priority.

Input

An integer t, 1<=t<=100, denoting the number of testcases, followed by t lines, each containing a space separated string consisting of T, F, and, or and xor of length less than 100 characters

Output

For each string given at input, display a line with the number of ways to parenthesize the expression such that it will evaluate to true.

Example

Input:
1
T and F

Output:
0

Added by:priyamehtanit
Date:2012-01-21
Time limit:1s-3s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:C++ 4.3.2 CPP
Resource:mit tutorial

hide comments
2018-05-29 11:52:51
Shit Man, No java
2017-01-11 12:58:27
Test cases seem too be very weak.Should go for a rejudge
2015-08-13 14:06:18 Ankit
nice problem to implement using dp
2014-10-28 23:33:07 Divyank Duvedi
test data is weak.....my code gave wrong answer for input string="T"...however it passed the given test data
2014-10-28 23:04:50 Divyank Duvedi
enjoyed solving this one :)
2013-10-21 03:09:09 Mauro Persano
There must be something wrong with the test cases... my solution just got accepted, and my output for T or F and T xor F is different from that of Marcelo or :D.

Last edit: 2013-10-21 03:09:43
2013-08-10 14:26:56 Akhilesh Anandh
Same output as :D :
1
2
0
5
37
1
0
2

Got accepted :)
2013-04-09 17:32:41 RAJDEEP GUPTA
My output is same as that of zukow.
(Output for T or T and F xor T and T or F is 37)
2013-03-24 19:34:59 Abhishek Verma
answer for :
T or T and F xor T and T or F
is 59..i got AC
@marcelo - correct your fourth last test case rest is fine
2013-03-05 15:02:56 Thotsaphon Thanatipanonda
Java please!!
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.