#include <bits/stdc++.h>

using namespace std;

#define all(x) begin(x), end(x)
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 2555, sigma = 4;
int dp[maxn][maxn][sigma];

int get(char c) {
	return c == 'R' ? 0 : c == 'G' ? 1 : 2;
}

class StringTransformation {
public:
	string getResult(string s, string t) {
		int n = s.size();
		int m = t.size();
		dp[0][0][0] = dp[0][0][1] = dp[0][0][2] = dp[0][0][3] = 1;
		for(int i = 1; i <= n; i++) {
			for(int j = 1; j <= m; j++) {
				if(s[i - 1] == t[j - 1]) {
					int c = get(s[i - 1]);
					dp[i][j][3] = dp[i - 1][j - 1][c];
				}
				for(int tc = 0; tc <= 2; tc++) {
					dp[i][j][tc] = dp[i][j][3];
					if(i >= 3 && get(s[i - 3]) != tc) {
						dp[i][j][tc] |= dp[i - 2][j][tc];
					}
				}
			}
		}
		return dp[n][m][3] ? "YES" : "NO";
	}
} me;