Given a binary string **S**. The task is to count the number of substrings that start and end with 1. For example, if the input string is “00100101”, then there are three substrings “1001”, “100101” and “101”.

**Input:**

The first line of input contains an integer T denoting the number of test cases. Each test case consist of an integer 'N' denoting the string length and next line is followed by a binary string.

**Output:**

For each testcase, in a new line, print the number of substring starting and ending with 1 in a separate line.

**User Task:**

The task is to complete the function **binarySubstring**() which counts the number of substrings starting and ending with 1 and returns count.

**Constraints:**

1 ≤ T ≤ 100

1 ≤ |S| ≤ 10^{4}

**Example:**

**Input:**

2

4

1111

5

01101

**Output:**

6

3

**Example:
Testcase 1:** There are 6 substrings from the given string. They are 11, 11, 11, 111, 111, 1111.

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.

ramabhatta | 35 |

Shubham Awasthi | 34 |

pguptacse17 | 30 |

abhithakur588 | 28 |

adityasuman2025 | 27 |

the_coder95 | 1236 |

RishabhTanwar1 | 1104 |

thanuvinu94 | 676 |

tathagat289 | 664 |

themanhasnoname | 620 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4889 |

Quandray | 4547 |

Login to report an issue on this page.