#include<bits/stdc++.h>
#define pb push_back
#define is insert
#define fi first
#define se second
#define mkp make_pair
#define INF INT_MAX
#define mem(a,b) memset(a,b,sizeof a)
#define cpy(a,b) memcpy(a,b,sizeof b)
#define mathmod(a,m) (((a)%(m)+(m))%(m))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int N=1e6+5;
int t,n,ans;
char s1[N],s2[N],t1[N],t2[N];
struct Seg{
	int l,r,cnt0,cnt1;
	vector<int> v;
	bool operator <(Seg _) const{return l<_.l;}
};
struct Seg3{int l,r,s1,s2;};
vector<Seg> seg1,seg2;
vector<Seg3> seg3;
void init(){
	ans=0;
	seg1.resize(0),seg2.resize(0),seg3.resize(0);
	mem(s1,0),mem(s2,0),mem(t1,0),mem(t2,0);
}
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>t;
	for(int cas=1;cas<=t;cas++){
		init();
		cin>>n>>(s1+1)>>(s2+1)>>(t1+1)>>(t2+1);
		t1[0]=t1[n+1]=t2[0]=t2[n+1]='0';
		for(int i=1;i<=n;i++){
			if(t1[i-1]=='0'&&t1[i+1]=='0') t1[i]='0',cout<<i<<endl;
			if(t2[i-1]=='0'&&t2[i+1]=='0') t2[i]='0',cout<<i<<endl;
		}
		for(int i=1;i<=n;i++) if(t1[i]=='0'&&t2[i]=='0'&&s1[i]==s2[i]) ans++;
		for(int i=1,lst1=-1,lst2=-1;i<=n+1;i++){
			if(t1[i]=='1'&&lst1==-1) lst1=i;
			else if(t1[i]=='0'&&lst1!=-1) seg1.pb((Seg){lst1,i-1,0,0,vector<int>()}),lst1=-1;
			if(t2[i]=='1'&&lst2==-1) lst2=i;
			else if(t2[i]=='0'&&lst2!=-1) seg2.pb((Seg){lst2,i-1,0,0,vector<int>()}),lst2=-1;
		}
		for(int i=1,lst=-1;i<=n+1;i++){
			if(t1[i]=='1'&&t2[i]=='1'&&lst==-1) lst=i;
			else if(!(t1[i]=='1'&&t2[i]=='1')&&lst!=-1){
				int blk1=prev(upper_bound(seg1.begin(),seg1.end(),(Seg){lst,0,0,0,vector<int>()}))-seg1.begin();
				int blk2=prev(upper_bound(seg2.begin(),seg2.end(),(Seg){lst,0,0,0,vector<int>()}))-seg2.begin();
				seg3.pb((Seg3){lst,i-1,blk1,blk2});
				lst=-1;
			}
		}
		for(auto &p:seg1){
			int l=p.l,r=p.r,cnt0=0,cnt1=0;
//			cout<<"DEBUG: "<<l<<" "<<r<<endl;
			for(int i=l;i<=r;i++){
				if(s1[i]=='0') cnt0++;
				else cnt1++;
			}
			for(int i=l;i<=r;i++) if(t2[i]=='0'){
				if(s2[i]=='0'&&cnt0) cnt0--,ans++,cout<<i<<endl;
				if(s2[i]=='1'&&cnt1) cnt1--,ans++,cout<<i<<endl;
			}
			p.cnt0=cnt0,p.cnt1=cnt1;
		}
//		cout<<"DEBUG: "<<ans<<endl;
		for(auto &p:seg2){
			int l=p.l,r=p.r,cnt0=0,cnt1=0;
//			cout<<"DEBUG: "<<l<<" "<<r<<endl;
			for(int i=l;i<=r;i++){
				if(s2[i]=='0') cnt0++;
				else cnt1++;
			}
			for(int i=l;i<=r;i++) if(t1[i]=='0'){
				if(s1[i]=='0'&&cnt0) cnt0--,ans++,cout<<i<<endl;
				if(s1[i]=='1'&&cnt1) cnt1--,ans++,cout<<i<<endl;
			}
			p.cnt0=cnt0,p.cnt1=cnt1;
		}
//		cout<<"DEBUG0: "<<ans<<endl;
		for(auto p:seg3) seg2[p.s2].v.pb(p.s1);
		for(auto &p:seg2){
			for(auto q:p.v){
				int cnt0=min(seg1[q].cnt0,p.cnt0);
				int cnt1=min(seg1[q].cnt1,p.cnt1);
				seg1[q].cnt0-=cnt0,p.cnt0-=cnt0;
				seg1[q].cnt1-=cnt1,p.cnt1-=cnt1;
				ans+=cnt0+cnt1;
			}
		}
		cout<<ans<<"\n";
	}
	cout<<flush;
	return 0;
}
/*
2
9
101111111
100111000
110111011
011111111
10
0110111100
1111111100
1110000100
0110111011
*/ 
