#include <bits/stdc++.h>
using namespace std;
int ch(vector<int> a, vector<int> b) {
  if (a.size() != b.size()) return 0;
  for (int i = 0; i < a.size(); i++)
    if (a[i] > b[i]) return 0;
  return 1;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    string a, b;
    cin >> a >> b;
    string q, w;
    q += a[0];
    w += b[0];
    vector<int> s, d;
    if (a[0] != b[0]) {
      cout << "NO\n";
      continue;
    }
    int cu = 1;
    for (int i = 1; i < a.length(); i++)
      if (a[i] != a[i - 1])
        q += a[i], s.push_back(cu), cu = 1;
      else {
        cu++;
      }
    s.push_back(cu);
    cu = 1;
    for (int i = 1; i < b.length(); i++)
      if (b[i] != b[i - 1])
        w += b[i], d.push_back(cu), cu = 1;
      else {
        cu++;
      }
    d.push_back(cu);
    cu = 1;
    if (q.length() == w.length() && ch(s, d)) {
      int f = 0;
      for (int i = 0; i < q.length(); i++) {
        if (q[i] != w[i]) {
          cout << "NO\n";
          f = 1;
          break;
        }
      }
      if (!f) cout << "YES\n";
      continue;
    }
    cout << "NO\n";
  }
  return 0;
}
