// .=*#=
// .=*=+* -#:
// -*+. += .#=
// -*= *- .#=
// :*= *#++#* .%:
// ++. *- =+ -#
// :*- *- *= %-
// .------::. -*. += -+++-. *#
// -*:-=+*#%#*++-. =+ -+ :+*- +@.
// :* .-++-:=++: ++ .# .*: +%-
// .# .:+#- .=*=. =+ *: :++. *+=
// % -%*=-=*. :*+. -* :* :++=. #-+
// #: .=*- .*: :*= .:==++++* +- -**+: :*:+
// += -#: *- :*- :=++=-:. =*- :+++- *-:+
// -# .=*- *- =*+*=: -*= == .# -#++++++++=-:
// @: =*: #: .. -*-# *: == .:-+++:
// ** :#: .#. .*@. =+ +: .-*+:
// :@: .=++=:. -* +. :# #. .+*:
// ## :-*@* +- .#. .# .++=-.
// :@+ =#*++-.# *: -+ .-+++-
// *%- #+- *. .-*+.
// .##- +@ -. .# .++.
// :*++ :% .=+. :*:*: :*-
// =+-*: - :++. .** =. +=
// =+.++: .++. #. == +=
// =+ .=*=. .*: *: *: *:
// -*. :++=: .#. #. .-*- .#
// :*: .=: *: += .-=+++++==++++=: *:
// .*= ... . += -++=:. :+
// -*: .. =++++==++++=: :*+++- #
// .++. == . .== .+%*=. %
// .*+== =#%= %
// :#* .:. -***..::. %
// #: +%@@: -*-+%++=--*- .#
// .*- :=*= -*- =%- *: -=
// =*=. =*- -* # .-. #.
// :=#*++++++++++++++++-:::-+*- #. .*+=#. ==
// *: .*- #----: == %+++++++++: -*
// % -*+- .#: #. +- -*
// % ##:+**. =*%. -% -+ ++
// *: #:+: :**-+= .## :* :*-
// :#=- +-# :*: .#:# :#. :*+.
// .*#+*+. :*. .*: % .#*+=: :*+.
// #..+ :*: #. .++ :+*-
// :**= # :++. == .*+. .:=++=.
// :=++*++=. .# .+%+==++++++-.
// *: .-+++++=-::..
// :* .=++=:.
// +- -*+:
// .#..=*-
// =#*:
// .-
#include <bits/stdc++.h>
#define prob ""
#define int long long
using namespace std;
void file(){
freopen(prob".INP", "r", stdin);
freopen(prob".OUT", "w", stdout);
}
void Init() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
//file();
}
void Sol() {
int q;
cin>>q;
while(q--){
int n;
cin>>n;
string s;
cin>>s;
vector<int>p;
for(int i=0;i<n;i++){
if(s[i]=='1'){
p.push_back(i);
}
}
if(p.empty()){
cout<<(n+2)/3<<'\n';
continue;
}
int t=p[0], res = p.size();
if(p[0]>=2){
res+=(p[0]+1)/3;
}
t=n-p.back()-1;
if(t>=2){
res+=(t+1)/3;
}
for(int i=0;i<p.size()-1;i++){
int temp=p[i+1]-p[i]-1;
res+=temp/3;
}
cout<<res<<'\n';
}
}
signed main(){
Init();
Sol();
return 0;
}