#include <bits/stdc++.h>
using namespace std;
int main() {
  iostream::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    string s, t;
    cin >> s;
    cin >> t;
    vector<pair<char, int>> st;
    vector<pair<char, int>> tt;
    int c = 0;
    char cc = '/';
    for (char i : s) {
      if (cc != i) {
        st.push_back(make_pair(cc, c));
        c = 1;
        cc = i;
      } else {
        ++c;
      }
    }
    st.push_back(make_pair(cc, c));
    c = 0;
    cc = '/';
    for (char i : t) {
      if (cc != i) {
        tt.push_back(make_pair(cc, c));
        c = 1;
        cc = i;
      } else {
        ++c;
      }
    }
    tt.push_back(make_pair(cc, c));
    bool is_possible = tt.size() == st.size();
    if (is_possible) {
      for (int i = 0; i < tt.size(); ++i) {
        if (tt[i].first != st[i].first || tt[i].second < st[i].second) {
          is_possible = false;
          break;
        }
      }
    }
    cout << (is_possible ? "YES" : "NO") << "\n";
  }
  return 0;
}
