Marin and Photoshoot

Today, Marin is at a cosplay exhibition and is preparing for a group photoshoot!

For the group picture, the cosplayers form a horizontal line. A group picture is considered beautiful if for every contiguous segment of at least 22 cosplayers, the number of males does not exceed the number of females (obviously).

Currently, the line has nn cosplayers which can be described by a binary string ss. The ii-th cosplayer is male if s_i = 0si​=0 and female if s_i = 1si​=1. To ensure that the line is beautiful, you can invite some additional cosplayers (possibly zero) to join the line at any position. You can't remove any cosplayer from the line.

Marin wants to know the minimum number of cosplayers you need to invite so that the group picture of all the cosplayers is beautiful. She can't do this on her own, so she's asking you for help. Can you help her?

Input

The first line contains a single integer tt (1 \leq t \leq 10^31≤t≤103) — the number of test cases.

The first line of each test case contains a positive integer nn (1 \leq n \leq 1001≤n≤100) — the number of cosplayers in the initial line.

The second line of each test case contains a binary string ss of length nn — describing the cosplayers already in line. Each character of the string is either 0 describing a male, or 1 describing a female.

Note that there is no limit on the sum of nn.

Output

For each test case, print the minimum number of cosplayers you need to invite so that the group picture of all the cosplayers is beautiful.

Sample 1

InputcopyOutputcopy
9
3
000
3
001
3
010
3
011
3
100
3
101
3
110
3
111
19
1010110000100000101
4
2
1
0
2
0
0
0
17

Note

In the first test case, for each pair of adjacent cosplayers, you can invite two female cosplayers to stand in between them. Then, 000 \rightarrow 0110110000→0110110.

In the third test case, you can invite one female cosplayer to stand next to the second cosplayer. Then, 010 \rightarrow 0110010→0110.

#include <iostream>
#include <cstring>
using namespace std;
int main()
{
	int t,n;
	cin>>t;
	char s[105];
	while(t--)
	{

		int ct=0;
		cin>>n;
		cin>>s;
		for(int i=0;i<n-1;i++)
		{
			if(s[i]=='0'&&s[i+1]=='0')
			{
				ct=ct+2;
			}
			else if(s[i-1]=='0'&&s[i]=='1'&&s[i+1]=='0')
			{
				ct++;
			}
		}
		cout<<ct<<endl;
	}
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

linalw

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值