#include<bits/stdc++.h>
using namespace std;
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int t,n;
	cin>>t>>n;
	for(int i=1;i<=t;i++){
		int ans=0;
		string s1,s2;
		cin>>s1>>s2;
		string t1,t2;
		cin>>t1>>t2;
		if(s1[0]=='1'){
			for(int j=0;j<n;j++){
				if(s2[j]=='1') ans++;
			}
		}
		else if(s1[0]=='0'){
			for(int j=0;j<n;j++){
				if(s2[j]=='0') ans++;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}
