#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t > 0) {
    string a, b;
    cin >> a >> b;
    int i;
    vector<pair<char, int>> va;
    for (i = 0; i < a.size(); i++) {
      int count = 1;
      while (a[i] == a[i + 1]) {
        i++;
        count++;
      }
      va.push_back(make_pair(a[i], count));
    }
    vector<pair<char, int>> vb;
    for (i = 0; i < b.size(); i++) {
      int count = 1;
      while (b[i] == b[i + 1]) {
        i++;
        count++;
      }
      vb.push_back(make_pair(b[i], count));
    }
    bool p = true;
    if (va.size() == vb.size()) {
      for (i = 0; i < va.size(); i++) {
        if (va[i].first == vb[i].first && vb[i].second >= va[i].second) {
          continue;
        } else
          p = false;
      }
      if (p)
        cout << "YES" << endl;
      else
        cout << "NO" << endl;
      ;
    } else {
      cout << "NO" << endl;
      ;
    }
    t--;
  }
}
