


The first line contains an integer ‘T’, which denotes the number of test cases to be run. Then, the T test cases follow.
The first line of each test case contains a single string, 'STR',
For each test case, print a single line containing a single integer, denoting the total number of substrings containing only ones.
The output for each test case will be printed in a separate line.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= |STR| <= 10 ^ 5
Where ‘T’ denotes the number of test cases and |STR| represents the total length of the string, ‘STR’.
Time Limit: 1 sec.
The approach is to find all substrings of the given string and then check each substring individually whether it contains all ones or not. We can check this by traversing through the entire string and if any character is zero, then this substring does not contain only ones. But if there is no zero in this substring then this substring contains only ones and thus we can increase the value of our answer by 1.
The approach is to observe the fact that if a string of length ‘N’ contains only ones, then this string also contains within itself, ‘N’ substrings of length 1, ‘N-1’ substrings of length 2, and so on and so forth till 1 substring of length ‘N’, which was also the original string. Let’s call this bigger string of length ‘N’, a block. So, a block of length ‘N’ contains (N*(N+1))/2 substrings containing only ones and we can add this value to our answer. Thus, we can calculate our final result by adding this value for every block.