#include<iostream>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<vector>
#define ll long long
using namespace std;
void solve()
{
//A. Marin and Photoshoot
ll n;
cin >> n;
string s;
cin >> s;
ll cnt = 0;
for (int i = 0; i < n; i++)
{
if (s[i] == '0' && s[i + 1] == '0')
cnt += 2;
else if (s[i] == '0' && s[i + 1] == '1' && s[i + 2] == '0')
cnt += 1;
}
cout << cnt << "
";
}
int main()
{
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}