Source Code
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Codeforces {

    static FastReader input = new FastReader();
    static final int INF = (int) 1e9 + 20;
    static long xe, ye, d;
    
    public static void main(String[] args) throws NumberFormatException, IOException {
        int t = input.nextInt();
        for(int z=0; z<t; z++){
            int n = input.nextInt();
            String a = input.next();
            String b = input.next();
            String first = simplify(a);
            String second = simplify(b);
            if(!first.equals(second)){
                System.out.println("no");
            }
            else{
                System.out.println("yes");
            }
        }
    }
    public static String simplify(String s){
        StringBuilder sb = new StringBuilder();
        int start = -1;
        for(int i=0; i<s.length(); i++){
            if(s.charAt(i) != '.' && start == -1){
                sb.append(s.charAt(i));
            }
            else if (s.charAt(i) == '.'){
                if(start == -1){
                    start = i-1;
                }
                continue;
            }
            else if (start != -1){
                if(sb.length() > 0){
                  sb.deleteCharAt(sb.length()-1);  
                }
                if((s.charAt(start) -'0')%2 == 1 && (s.charAt(start) -'0')%2 == 0){
                    sb.append(s.substring(start, i+1));
                }
                else{
                    sb.append(s.charAt(start));
                    sb.append(s.charAt(i));
                }
                start = -1;
            }
        }
        return sb.toString();
    }
    public static void swap(char[] arr, int i, int j){
        char temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
    
    static class FastReader {
 
        BufferedReader br;
        StringTokenizer st;
 
        public FastReader() {
            /*try {
             br = new BufferedReader(new FileReader(new File("travel_restrictions_validation_input.txt")));
             } catch (FileNotFoundException e) {
             e.printStackTrace();
             }*/
            br = new BufferedReader(new InputStreamReader(System.in));
        }
 
        String next() throws IOException {
            while (st == null || !st.hasMoreElements()) {
                st = new StringTokenizer(br.readLine());
            }
            return st.nextToken();
        }
 
        int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }
 
        long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }
 
        double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
 
        String nextLine() throws IOException {
            String str = "";
            str = br.readLine();
            return str;
        }
 
        boolean hasNext() throws IOException {
            return br.ready();
        }
    }
}
Copy
Moving Digits Catwoman
Java 11
109 ms
14.2 MB
Wrong Answer