We are given a string str consisting of digits, we may group these digits into sub-groups (but maintaining their original order). The task is to count number of groupings such that for every sub-group except the last one, sum of digits in a sub-group is less than or equal to sum of the digits in the sub-group immediately on its right.

For example, a valid grouping of digits of number 1119 is (1-11-9). Sum of digits in first subgroup is 1, next subgroup is 2, and last subgroup is 9. Sum of every subgroup is less than or equal to its immediate right.

**Input:**

The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. The first line of each test case contains an integer N denoting the length of the string str.

The second line of each test case contains the string str.It consists of numerals from 0 to 9.

**Output:**

Print the answer for each test case in a new line.

**Constraints:**

1<= T <=100

1<= N <=100

**Example:**

Input:

1

4

1119

Output:

7

Explanation:

```
Sub-groups: [1-119], [1-1-19], [1-11-9], [1-1-1-9],
[11-19] and [111-9].
Note : Here we have included [1119] in the group and
sum of digits is 12 and this group has no
immediate right.
```

Author: sujnesh

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 | 467 |

kunalk02141 | 429 |

RishabhTanwar1 | 384 |

the_coder95 | 380 |

RitikRosan | 288 |

the_coder95 | 1226 |

RishabhTanwar1 | 1104 |

thanuvinu94 | 676 |

tathagat289 | 652 |

themanhasnoname | 620 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4885 |

Quandray | 4547 |

Login to report an issue on this page.