Given a string **S** of digits(0-9), your task is to find the **maximum value** that can be obtained from the string by putting either** '*' or '+' **operators in between the digits while traversing from left to right of the string and picking up a single digit at a time.

**Input:**

The first line of input contains **T** denoting the number of testcases. **T** testcases follow. Each testcase contans one line of input denoting the string.

**Output:**

For each testcase, print the maximum value obtained.

**Constraints:**

1 <= T <= 100

1 <= |S|< = 20

0 <= Digits <= 9

**Example:**

**Input:**

2

01230

891

**Output:**

9

73

**Explanation:**

**Testcase1:** we have 01230. We traverse from left and pick zero. Now we encounter 1. We see if 0*1 gives maximum or 0+1. Now we have ans as 1. Now we traverse further. We encounter 2. Now 1*2 gives max or 1+2. Now we have ans 3. Now we traverse further. We encounter 3. We see if 3*3 gives max or 3+3. The ans is now 9. Now we traverse fiurther. We encounter 0, we see if 9+0 gives max or 9*0. The ans is now 9. We've traversed whole string so we stop.

Author: Sahil_Chhabra

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

thanuvinu94 | 425 |

the_coder95 | 380 |

RishabhTanwar1 | 320 |

kunalk02141 | 306 |

RitikRosan | 272 |

the_coder95 | 1226 |

RishabhTanwar1 | 1040 |

tathagat289 | 636 |

thanuvinu94 | 634 |

themanhasnoname | 620 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4885 |

Quandray | 4547 |

Login to report an issue on this page.