#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s, a;
    int d = 0;
    cin >> s >> a;
    vector<pair<char, int> > v, w;
    for (int i = 0; i < s.size(); i++) {
      int j = i + 1;
      if (s[i] == s[i + 1] && i + 1 < s.size()) {
        for (j = i + 1; j < s.size(); j++)
          if (s[j] != s[i]) break;
        v.push_back(make_pair(s[i], j - i));
      } else
        v.push_back(make_pair(s[i], 1));
      i = j - 1;
    }
    for (int i = 0; i < a.size(); i++) {
      int j = i + 1;
      if (a[i] == a[i + 1] && i + 1 < a.size()) {
        for (j = i + 1; j < a.size(); j++)
          if (a[j] != a[i]) break;
        w.push_back(make_pair(a[i], j - i));
      } else
        w.push_back(make_pair(a[i], 1));
      i = j - 1;
    }
    if (v.size() != w.size())
      cout << "NO\n";
    else {
      for (int i = 0; i < v.size(); i++) {
        if (v[i].first == w[i].first && v[i].second <= w[i].second)
          continue;
        else {
          d = 1;
          break;
        }
      }
      if (d)
        cout << "NO\n";
      else
        cout << "YES\n";
    }
  }
  return 0;
}
