#include <bits/stdc++.h>
using namespace std;
queue<pair<int, int> > q1, q2;
int t;
int main() {
  cin >> t;
  while (t--) {
    string a, b;
    bool x = 1;
    cin >> a >> b;
    int lg = 1;
    for (int i = 1; i < a.size(); i++) {
      if (a[i] != a[i - 1]) {
        q1.push({i - 1, lg});
        lg = 0;
      }
      lg++;
    }
    q1.push({a.size() - 1, lg});
    lg = 1;
    for (int i = 1; i < b.size(); i++) {
      if (b[i] != b[i - 1]) {
        q2.push({i - 1, lg});
        lg = 0;
      }
      lg++;
    }
    q2.push({b.size() - 1, lg});
    while (!q1.empty() && !q2.empty()) {
      if (a[q1.front().first] != b[q2.front().first]) {
        x = 0;
        break;
      } else if (q1.front().second > q2.front().second) {
        x = 0;
        break;
      }
      q1.pop();
      q2.pop();
    }
    if (!q1.empty()) {
      x = 0;
    }
    if (!q2.empty()) {
      x = 0;
    }
    if (x) {
      cout << "YES\n";
    } else {
      cout << "NO\n";
    }
    while (!q1.empty()) {
      q1.pop();
    }
    while (!q2.empty()) {
      q2.pop();
    }
  }
  return 0;
}
