#include <bits/stdc++.h>
using namespace std;
vector<long long int> v;
string fun(string s, string sp) {
  string s1 = "";
  int cnt = 0;
  for (int i = 0; i < s.size(); i++) {
    if (i == 0) {
      if (s[i] == sp[cnt]) {
        s1 += s[i];
        cnt++;
      } else {
        s1 += '9';
        return s1;
      }
    } else {
      if (s[i] == sp[cnt]) {
        cnt++;
        s1 += s[i];
      } else {
        if (s[i] != sp[cnt - 1]) {
          s1 += "9";
          return s1;
        }
      }
    }
  }
  return s1;
}
int main() {
  int t, c = 0;
  scanf("%d", &t);
  while (t--) {
    string s, s1;
    cin >> s >> s1;
    s1 = fun(s1, s);
    if (s == s1)
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}
