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