#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
template <class T>
inline void chmax(T &a, const T &b) {
  if ((a) < (b)) (a) = (b);
}
template <class T>
inline void chmin(T &a, const T &b) {
  if ((a) > (b)) (a) = (b);
}
template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast {
  Fast() {
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
long long query(string s, string t) {
  long long n = ((long long)(s).size());
  long long m = ((long long)(t).size());
  if (n > m) {
    cout << "NO" << endl;
    return 0;
  }
  vector<char> schar, tchar;
  vector<long long> scnt, tcnt;
  char pre = ':';
  long long cnt = 0;
  for (long long i = (long long)(0); i < (long long)(n); ++i) {
    if (s[i] == pre) {
      cnt++;
    } else {
      if (i - 1 >= 0) {
        schar.push_back(s[i - 1]);
        scnt.push_back(cnt);
      }
      cnt = 1;
    }
    pre = s[i];
  }
  schar.push_back(s[n - 1]);
  scnt.push_back(cnt);
  pre = ':';
  cnt = 0;
  for (long long i = (long long)(0); i < (long long)(m); ++i) {
    if (t[i] == pre) {
      cnt++;
    } else {
      if (i - 1 >= 0) {
        tchar.push_back(t[i - 1]);
        tcnt.push_back(cnt);
      }
      cnt = 1;
    }
    pre = t[i];
  }
  tchar.push_back(t[m - 1]);
  tcnt.push_back(cnt);
  42;
  42;
  42;
  42;
  if (((long long)(schar).size()) != ((long long)(tchar).size())) {
    cout << "NO" << endl;
    return 0;
  }
  for (long long i = (long long)(0);
       i < (long long)(((long long)(schar).size())); ++i) {
    if (schar[i] == tchar[i] and scnt[i] <= tcnt[i]) {
    } else {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
long long solve() {
  long long q;
  cin >> q;
  for (long long _ = (long long)(0); _ < (long long)(q); ++_) {
    string s, t;
    cin >> s >> t;
    query(s, t);
  }
  return 0;
}
signed main() {
  solve();
  return 0;
}
