在西元800年左右,巴格達的一個商人El Mamum手上有一個公式:1+2*3*4+5,這個公式是用來做為駱駝交易的。由於這個公式沒有括號來決定運算的先後順序,所以答案可能有很多種。所以,他要求僕人提供他一個方法來解析這個公式,好讓他可以在買賣駱駝時獲益最大。
你受 El Mamum 的委託寫一個程式找出一個不含括號的公式可能的解析結果中最大值及最小值分別是多少。
Input
輸入的第一列有一個正整數,代表以下有多少組測試資料。
每組測試資料最多有 12 個數字,每個數字均介於 1 到 20 之間。這些數字中以 加號(+) 或 乘號(*) 來分隔。
請參考 Sample Input。
Output
對每組測試資料輸出一列,公式可能的解析結果中最大值及最小值。輸出格式請參考Sample Output。
Sample Input
5
1+2*3*4+5
4*18+14+7*10
3+11+4*1*13*12*8+3*3+8
20*20*20*20*20*20*20*20*20*20*20*20
1+2+3+4+5
Sample Output
The maximum and minimum are 81 and 30. The maximum and minimum are 1560 and 156. The maximum and minimum are 339768 and 5023. The maximum and minimum are 4096000000000000 and 4096000000000000. The maximum and minimum are 15 and 15.