#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  long int n, i, y = 1;
  cin >> n;
  string s, t;
  char p;
  queue<char> q1, q2;
  for (i = 0; i < n; i++) {
    y = 1;
    cin >> s >> t;
    long int j, c = 0;
    for (j = 0; s[j] != 0; j++) {
      q1.push(s[j]);
    }
    for (j = 0; t[j] != 0; j++) {
      q2.push(t[j]);
    }
    while (!q1.empty()) {
      c = 0;
      p = q1.front();
      while (!q1.empty() && p == q1.front()) {
        c++;
        q1.pop();
      }
      if (!q2.empty() && q2.front() != p) {
        cout << "NO"
             << "\n";
        y = 0;
        break;
      }
      while (!q2.empty() && p == q2.front()) {
        c--;
        q2.pop();
      }
      if (c > 0) {
        cout << "NO"
             << "\n";
        y = 0;
        break;
      }
    }
    if (y) {
      if (!q2.empty())
        cout << "NO"
             << "\n";
      else
        cout << "YES"
             << "\n";
    }
    while (!q1.empty()) q1.pop();
    while (!q2.empty()) q2.pop();
  }
}
