#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long i, j, k, l, n, m, b, c, d;
  string s, t;
  cin >> s >> t;
  if (s[0] != t[0]) {
    cout << "NO\n";
    return;
  }
  for (j = 1, i = 1; s[i] != 0; i++, j++) {
    for (; t[j] != s[i] && t[j] != 0; j++)
      if (t[j] != s[i - 1]) {
        cout << "NO\n";
        return;
      };
    if (t[j] == 0) {
      cout << "NO\n";
      return;
    }
  }
  for (; t[j] == s[i - 1] && t[j] != 0; j++)
    ;
  if (t[j] != 0)
    cout << "NO\n";
  else
    cout << "YES\n";
  return;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
