#include
#include
using namespace std;
const int maxn = 1005;
string a, b;
int dp[maxn][maxn][2];
int rec(int at_A, int at_B, bool to_uppercase) {
if(at_B == -1) {
if(!to_uppercase) {
if(at_A == -1) {
return 1;
}
return 0;
}
return 1;
}
if(at_A == -1) {
return 0;
}
if(dp[at_A][at_B][to_uppercase] != -1) {
return dp[at_A][at_B][to_uppercase];
}
int result = 0;
if(a[at_A] == b[at_B]) {
result = max(result, rec(at_A - 1, at_B - 1, false));
}
if(toupper(a[at_A]) == b[at_B]) {
result = max(result, rec(at_A - 1, at_B - 1, true));
}
if(islower(a[at_A])) {
result = max(result, rec(at_A - 1, at_B, to_uppercase));
}
return dp[at_A][at_B][to_uppercase] = result;
}
int main() {
ios_base::sync_with_stdio(false);
int q;
cin >> q;
while(q--) {
cin >> a >> b;
memset(dp, -1, sizeof dp);
if(rec((int)a.size() - 1, (int)b.size() - 1, true)) {
cout << "YES" << endl;
}
else {
cout << "NO" << endl;
}
}
return 0;
}