#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  while (n--) {
    string f, s;
    cin >> f >> s;
    string x = "";
    string y = "";
    x += f[0];
    y += s[0];
    for (int i = 1; i < f.size(); i++) {
      if (f[i] != f[i - 1]) x += f[i];
    }
    for (int i = 1; i < s.size(); i++) {
      if (s[i] != s[i - 1]) y += s[i];
    }
    if (x == y) {
      int n = x.size();
      int a[n], b[n];
      int idx1 = -1, idx2 = -1;
      int c1 = 0, c2 = 0;
      for (int i = 1; i < f.size(); i++) {
        if (f[i] == f[i - 1]) {
          c1++;
          continue;
        } else {
          idx1++;
          a[idx1] = (c1 + 1);
          c1 = 0;
        }
      }
      a[n - 1] = c1 + 1;
      for (int i = 1; i < s.size(); i++) {
        if (s[i] == s[i - 1]) {
          c2++;
          continue;
        } else {
          idx2++;
          b[idx2] = c2 + 1;
          c2 = 0;
        }
      }
      b[n - 1] = c2 + 1;
      int f = 0;
      for (int i = 0; i < n; i++) {
        if (b[i] >= a[i])
          continue;
        else {
          f = 1;
          break;
        }
      }
      if (!f)
        cout << "YES" << endl;
      else
        cout << "NO" << endl;
    } else
      cout << "NO" << endl;
  }
}
