#include <bits/stdc++.h>
using namespace std;
void f() {
  string a, b;
  cin >> a >> b;
  vector<pair<char, int>> aa, bb;
  for (char c : a) {
    if (aa.empty() || aa.back().first != c)
      aa.push_back(make_pair(c, 1));
    else
      aa.back().second++;
  }
  for (char c : b) {
    if (bb.empty() || bb.back().first != c)
      bb.push_back(make_pair(c, 1));
    else
      bb.back().second++;
  }
  if (aa.size() != bb.size()) {
    cout << "NO\n";
  } else {
    for (int i = 0; i < aa.size(); i++) {
      if (aa[i].first != bb[i].first || aa[i].second > bb[i].second) {
        cout << "NO\n";
        return;
      }
    }
    cout << "YES\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  while (n--) {
    f();
  }
}
