1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int INF=1e9+7;
void solve() {
	int n;
	string s;
	cin >> n >> s;
	int akt=0, ans=0;
	priority_queue<pair<int,int>>q;
	rep(i, n) {
		if(s[i]=='1') {
			if(akt) {
				if(akt==i) {
					q.push({akt, INF});
				} else {
					q.push({(akt+1)/2, akt});
				}
			}
			akt=0;
		} else ++akt;
	}
	if(0<akt && akt<n) {
		q.push({akt, INF});
	}
	if(akt==n) {
		cout << 0 << '\n';
		return;
	}
	akt=0;
	while(!q.empty()) {
		int a=q.top().st, b=q.top().nd; q.pop();
		if(akt>=a) break;
		if(b==INF) {
			ans+=a-akt;
			++akt;
		} else {
			ans+=max(1, b-2*akt-1);
			akt+=2;
		}
	}
	cout << n-ans << '\n';
}
int32_t main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int _;
	cin >> _;
	while(_--) solve();
}