Source Code
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

const int inf = 1e9;
const ll infll = 1e18;
const int M = 1000000007;
const int N = 2e5;

void testCase(){
	int n;
	string s[2], tmp[2] = {"", ""};
	cin >> n >> s[0]>> s[1];
	vector<pair<int,int>> v[2];
	for (int i = 0; i < 2; ++i){
		for (int j = 0; j < n; ++j){
			if(s[i][j] == '.')continue;
			v[i].pb({s[i][j] - '0', j});
			tmp[i] += s[i][j];
		}
	}
	if(tmp[0] != tmp[1])return (void) puts("no");
	for (int i = 0; i < v[0].size(); ++i){
		if(v[0][i].f%2 == 0 && v[0][i].s > v[1][i].s) return (void) puts("no");
		if(v[0][i].f%2 == 1 && v[0][i].s < v[1][i].s) {
			//cout << v[0][i].s << endl;
			return (void) puts("no");
		}
	}
	puts("yes");
	
}

int main(){
	int T = 1;
	scanf("%d", &T);
	while(T--){
		testCase();
	} 
}	
Copy
Moving Digits Hambubger
GNU G++17
68 ms
3.9 MB
Accepted