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.

narahc321 | 170 |

agness | 163 |

lonecoder | 153 |

2016uec1342 | 142 |

HuHu | 140 |

lonecoder | 1088 |

nikhil_sojan | 1082 |

KshatriyaYash | 1066 |

mazumderrohit8 | 928 |

SumitSingh27 | 832 |

blackshadows | 5327 |

Ibrahim Nash | 5215 |

akhayrutdinov | 5111 |

mb1973 | 4504 |

Quandray | 4444 |

Login to report an issue on this page.