#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  for (int(_) = 0; (_) < (n); (_)++) {
    string S, T;
    cin >> S >> T;
    S.push_back('A');
    T.push_back('A');
    vector<pair<char, int> > sl, tl;
    char ns = S[0];
    int cs = 1;
    for (int i = 1; i <= (int)(((int)(S).size()) - 1); i++) {
      if (S[i] == ns)
        cs++;
      else {
        sl.push_back(make_pair(ns, cs));
        ns = S[i];
        cs = 1;
      }
    }
    char nt = T[0];
    int ct = 1;
    for (int i = 1; i <= (int)(((int)(T).size()) - 1); i++) {
      if (T[i] == nt)
        ct++;
      else {
        tl.push_back(make_pair(nt, ct));
        nt = T[i];
        ct = 1;
      }
    }
    bool ans = true;
    if (((int)(sl).size()) != ((int)(tl).size())) ans = false;
    for (int(i) = 0; (i) < (((int)(sl).size())); (i)++) {
      if (sl[i].first != tl[i].first) ans = false;
      if (sl[i].second > tl[i].second) ans = false;
    }
    if (ans)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}
