#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int infi = 1147483600;
const long long infl = 1e17;
const char ENDL = '\n';
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  for (long long xx = 0; xx < (long long)n; xx++) {
    string s, t;
    cin >> s >> t;
    vector<pair<int, int> > sd, td;
    int bef = s[0] - 'a', cnt = 1;
    for (long long i = (long long)1; i < (long long)s.size(); i++) {
      int si = s[i] - 'a';
      if (si == bef)
        cnt++;
      else {
        sd.emplace_back(make_pair(bef, cnt));
        bef = si;
        cnt = 1;
      }
    }
    sd.emplace_back(make_pair(bef, cnt));
    bef = t[0] - 'a';
    cnt = 1;
    for (long long i = (long long)1; i < (long long)t.size(); i++) {
      int ti = t[i] - 'a';
      if (ti == bef)
        cnt++;
      else {
        td.emplace_back(make_pair(bef, cnt));
        bef = ti;
        cnt = 1;
      }
    }
    td.emplace_back(make_pair(bef, cnt));
    if (sd.size() != td.size()) {
      cout << "NO" << ENDL;
      continue;
    }
    bool flag = true;
    for (long long i = 0; i < (long long)sd.size(); i++) {
      if (sd[i].first != td[i].first) {
        flag = false;
        break;
      }
      if (sd[i].second > td[i].second) {
        flag = false;
        break;
      }
    }
    if (flag)
      cout << "YES" << ENDL;
    else
      cout << "NO" << ENDL;
  }
}
