LISA - Pocket Money

Young people spend a lot of money on things like sweets, music CDs, mobile phones and so on. But most young girls/boys have one problem: Their pocket money is not enough for all these jolly things. Little Lisa Listig is one of these poor girls with a small pocket money budget. Last month her pocket money lasted only one week. So she decided to enter into negotiations with her father. Her father Tomm - a mathematician - had an incredibly ingenious idea: He wrote down some fancy digits with operators (+, *) in between them on a sheet of paper and allowed Lisa to insert brackets. Then he declared that the result of that arithmetic expression is Lisa's new pocket money. Now it's Lisa's task to maximize her pocket money. As her father was surprised what a huge sum of money Lisa got for her result, he decided to minimize the result of the expression for his son Manfred. Now it's your task to calculate the results obtained by Lisa and her father.

Input

The first line of input contains the number of testcases k (k< 5000). Each of the following k lines consists of an arithmetic expression. This expression consists of numbers (0-9) separated by one of the two operators '*' and '+'. There are no spaces between the characters. Each line contains less than 100 characters.

Output

For each expression output the result obtained by Lisa and the result obtained by her father separated by one space. The results of the calculations are smaller than 264.

Example

Input:
1
1+2*3+4*5

Output:
105 27

Two possible expressions for the first testcase:

105 = (1+2)*(3+4)*5
27  = 1+2*3+4*5

Added by:Simon
Date:2005-05-17
Time limit:32s
Source limit:8082B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL GOSU JS-RHINO
Resource:Ulm Algorithm Course SoSe 2005

hide comments
2023-08-22 16:15:37
@sharif ullah comment is great and motivated me. I have gained some new speed. MCM the forgotten DP hero.
2021-03-04 11:26:30
After my comment @sharif ullah's comment will at page 2.But If you will not able to solve problem then go and watch his comment .Maybe that will give you motivation . LOL :)
2020-12-21 14:16:56
AC after 8 months. Understood MCM properly now
2020-11-13 15:40:43
so many AC's in 1 go....lol just makes me laugh
2020-09-18 09:28:11
@sfialok98 Thanks for the test case!
2020-08-20 08:13:15
where can we get to know about failed test case for our code
2020-03-02 18:14:18
AC in 1 Go!
2020-01-20 05:09:09
2 times (mcm) easy peasy TOP DOWN 0.11
2019-01-18 18:02:42
simple question. just read MCM once then you can do it in one go.... i got AC in one go
2018-11-14 08:23:04
@sharif ullah's comment is the most helpful guys.
Go and study MCM a bit, i didn't know what it is one hour ago, but now i got AC in this problem in one GO. :)
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.