#include <bits/stdc++.h>
using namespace std;
bool check(string str1, string str2) {
  vector<pair<char, int> > V1, V2;
  char last = '#';
  int cnt = 0;
  for (int i = 0; i < str1.size(); i++) {
    if (str1[i] == last)
      cnt++;
    else {
      if (cnt != 0) {
        V1.push_back(make_pair(last, cnt));
      }
      cnt = 1;
    }
    last = str1[i];
  }
  V1.push_back(make_pair(last, cnt));
  last = '#';
  cnt = 0;
  for (int i = 0; i < str2.size(); i++) {
    if (str2[i] == last)
      cnt++;
    else {
      if (cnt != 0) {
        V2.push_back(make_pair(last, cnt));
      }
      cnt = 1;
    }
    last = str2[i];
  }
  V2.push_back(make_pair(last, cnt));
  if ((int)V1.size() != (int)V2.size()) return false;
  for (int i = 0; i < (int)V1.size(); i++) {
    if (V1[i].first != V2[i].first) return false;
    if (V1[i].second > V2[i].second) return false;
  }
  return true;
}
int main() {
  int cases;
  scanf("%d", &cases);
  while (cases--) {
    string s1, s2;
    cin >> s1 >> s2;
    if (check(s1, s2))
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}
