#include #include #include #include #include #include #include #include #include #include #include #include #define SZ(X) ((int)(X).size()) #define ALL(X) (X).begin(), (X).end() #define REP(I, N) for (int I = 0; I < (N); ++I) #define REPP(I, A, B) for (int I = (A); I < (B); ++I) #define RI(X) scanf("%d", &(X)) #define RII(X, Y) scanf("%d%d", &(X), &(Y)) #define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z)) #define DRI(X) int (X); scanf("%d", &X) #define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y) #define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z) #define RS(X) scanf("%s", (X)) #define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0) #define MP make_pair #define PB push_back #define MS0(X) memset((X), 0, sizeof((X))) #define MS1(X) memset((X), -1, sizeof((X))) #define LEN(X) strlen(X) #define PII pair #define VI vector #define VPII vector > #define PLL pair #define VPLL vector > #define F first #define S second typedef long long LL; using namespace std; const int MOD = 1e9+7; const int SIZE = 1e6+10; char s[SIZE]; int dp[101][101][51]; template void maa(T& x,T y){ if(x void mii(T& x,T y){ if(x>y)x=y; } int main(){ CASET{ DRII(n,m); m/=2; RS(s); VI d; REP(i,n)if(s[i]=='2')d.PB(n-i); reverse(ALL(d)); REP(i,SZ(d)+1)REP(j,n+1)REP(k,m+1)dp[i][j][k]=-1; dp[0][0][0]=0; REP(i,SZ(d)){ REPP(j,1,n+1)REP(k,m+1)maa(dp[i][j][k],dp[i][j-1][k]); REP(k,m+1){ REPP(k2,max(1,d[i]-(m-k)),min(n,d[i]+(m-k))+1){ if(k2>=3&&dp[i][k2-3][k]!=-1)maa(dp[i+1][k2][k+abs(d[i]-k2)],dp[i][k2-3][k]+1); maa(dp[i+1][k2][k+abs(d[i]-k2)],dp[i][k2-1][k]); } } } int an=0; REP(i,n+1) REP(j,m+1)maa(an,dp[SZ(d)][i][j]); printf("%d\n",an); } return 0; }