#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n; cin>>n;
    string a, b, c; cin>>a>>b>>c;
    vector<char> C = {'J', 'O', 'I'};
    
    auto f = [&](string x, string y){
        string t;
        for (int i = 0; i < n; i++){
            if (x[i] == y[i]){
                t += x[i];
                continue;
            }
            for (char s: C){
                if (s != x[i] && s != y[i]){
                    t += s;
                    break;
                }
            }
        }
        return t;
    };
    
    vector<string> all = {a, b, c, f(a, b), f(b, c), f(a, c), f(f(a, b), c), f(f(b, c), a), f(f(a, c), b)};
    int q; cin>>q;
    string t; cin>>t;
    
    auto check = [&](string s){
        for (string x: all){
            if (s == x){
                cout<<"Yes"<<"\n";
                return;
            }
        }
        cout<<"No"<<"\n";
    };
    
    check(t);
    
    while (q--){
        int l, r; char S; cin>>l>>r>>S;
        l--; r--;
        for (int i = l; i <= r; i++){
            t[i] = S;
        }
        
        check(t);
    }
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |