#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string a, b;
    cin >> a >> b;
    if (b.size() < a.size()) {
      cout << "NO" << endl;
      continue;
    }
    vector<pair<char, int> > c, d;
    int atual = 0;
    for (int j = 0; j < a.size(); j++) {
      if (j == 0) {
        c.push_back({a[j], 1});
      } else {
        if (a[j] == a[j - 1]) {
          c[atual].second++;
        } else {
          atual++;
          c.push_back({a[j], 1});
        }
      }
    }
    atual = 0;
    for (int j = 0; j < b.size(); j++) {
      if (j == 0) {
        d.push_back({b[j], 1});
      } else {
        if (b[j] == b[j - 1]) {
          d[atual].second++;
        } else {
          atual++;
          d.push_back({b[j], 1});
        }
      }
    }
    if (c.size() != d.size()) {
      cout << "NO" << endl;
      continue;
    }
    bool ok = true;
    for (int j = 0; j < c.size(); j++) {
      if (c[j].first != d[j].first) {
        ok = false;
        break;
      } else if (c[j].first == d[j].first) {
        if (d[j].second < c[j].second) {
          ok = false;
          break;
        }
      }
    }
    if (ok)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
