#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    string s;
    cin >> s;
    string t;
    cin >> t;
    int n = s.size(), nn = t.size();
    if (n > nn) {
      cout << "NO\n";
      continue;
    }
    vector<string> store;
    string ss{};
    char prev = t[0];
    ss += prev;
    for (int j = 0; j < nn; ++j) {
      if (t[j] == prev) {
        ss += prev;
      } else {
        store.push_back(ss);
        ss = t[j];
        prev = t[j];
      }
    }
    store.push_back(ss);
    vector<string> store_2;
    ss = "";
    prev = s[0];
    ss += prev;
    for (int j = 0; j < n; ++j) {
      if (s[j] == prev) {
        ss += prev;
      } else {
        store_2.push_back(ss);
        ss = s[j];
        prev = s[j];
      }
    }
    store_2.push_back(ss);
    int m = store.size();
    if (m != store_2.size()) {
      cout << "NO\n";
      continue;
    }
    for (int j = 0; j < m; ++j) {
      if (store[j][0] != store_2[j][0] || store[j].size() < store_2[j].size()) {
        cout << "NO\n";
        goto done;
      }
    }
    cout << "YES\n";
  done:;
  }
  return 0;
}
