#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
using namespace std;
mt19937 rnd(time(0));
int gcd(int a, int b) {
  if (!b)
    return a;
  else
    return gcd(b, a % b);
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
const int N = 3e5 + 10, INF = 2e9 + 7;
vector<pair<int, int> > a, b;
void solve() {
  a.clear();
  b.clear();
  string s1, s2;
  cin >> s1 >> s2;
  for (int i = 0; i < (int)(s1).size(); i++) {
    if (i == 0) {
      a.push_back(make_pair(s1[0], 1));
      continue;
    }
    if (s1[i] == s1[i - 1]) {
      a.back().second++;
    } else {
      a.push_back(make_pair(s1[i], 1));
    }
  }
  for (int i = 0; i < (int)(s2).size(); i++) {
    if (i == 0) {
      b.push_back(make_pair(s2[0], 1));
      continue;
    }
    if (s2[i] == s2[i - 1]) {
      b.back().second++;
    } else {
      b.push_back(make_pair(s2[i], 1));
    }
  }
  if ((int)(a).size() != (int)(b).size()) {
    cout << "NO\n";
    return;
  }
  for (int i = 0; i < (int)(a).size(); i++) {
    if (a[i].first != b[i].first) {
      cout << "NO\n";
      return;
    }
    if (a[i].second > b[i].second) {
      cout << "NO\n";
      return;
    }
  }
  cout << "YES\n";
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    solve();
  }
  return 0;
}
