#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, i;
  cin >> t;
  while (t--) {
    string s, s1;
    cin >> s >> s1;
    long long int a = s.size();
    long long int b = s1.size();
    vector<pair<int, int> > v, v1;
    int c = 1;
    for (i = 1; i < a; i++) {
      if (s[i] != s[i - 1]) {
        v.push_back({s[i - 1], c});
        c = 1;
      } else
        c++;
    }
    v.push_back({s[i - 1], c});
    c = 1;
    for (i = 1; i < b; i++) {
      if (s1[i] != s1[i - 1]) {
        v1.push_back({s1[i - 1], c});
        c = 1;
      } else
        c++;
    }
    v1.push_back({s1[i - 1], c});
    int d = 0;
    if (v.size() != v1.size()) d = 1;
    for (i = 0; i < v.size(); i++) {
      if (v[i].first != v1[i].first || v[i].second > v1[i].second) d = 1;
    }
    if (d == 1)
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
  return 0;
}
