#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long N;
  cin >> N;
  for (long long test = 0; test < N; ++test) {
    string S, T;
    cin >> S >> T;
    vector<pair<char, long long>> s, t;
    char before = S.at(0);
    long long cnt = 0;
    for (long long i = 0; i < S.size(); ++i) {
      if (S.at(i) != before) {
        s.push_back({before, cnt});
        before = S.at(i);
        cnt = 1;
      } else {
        cnt += 1;
      }
    }
    s.push_back({before, cnt});
    before = T.at(0);
    cnt = 0;
    for (long long i = 0; i < T.size(); ++i) {
      if (T.at(i) != before) {
        t.push_back({before, cnt});
        before = T.at(i);
        cnt = 1;
      } else {
        cnt += 1;
      }
    }
    t.push_back({before, cnt});
    bool ok = true;
    if (s.size() != t.size()) {
      ok = false;
    } else {
      for (long long i = 0; i < s.size(); ++i) {
        if (s.at(i).first != t.at(i).first) {
          ok = false;
        }
        if (s.at(i).second > t.at(i).second) {
          ok = false;
        }
      }
    }
    if (ok) {
      cout << "YES"
           << "\n";
    } else {
      cout << "NO"
           << "\n";
    }
  }
}
