#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, n, a, a1, ctr, ctr1, l;
  string c1, c;
  char d;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> c >> c1;
    a = c.size();
    a1 = c1.size();
    if (a1 < a)
      cout << "NO";
    else {
      a--;
      a1--;
      l = 0;
      ctr = 0;
      ctr1 = 0;
      while (a >= 0 and a1 >= 0 and l == 0) {
        ctr = 0;
        ctr1 = 0;
        d = c[a];
        if (c[a] != c1[a1]) l = 1;
        while (c[a] == d) {
          a--;
          ctr++;
        }
        while (c1[a1] == d) {
          a1--;
          ctr1++;
        }
        if (ctr > ctr1) l = 1;
      }
      if (a1 != a) l = 1;
      if (l == 0)
        cout << "YES";
      else
        cout << "NO";
    }
    cout << '\n';
  }
  return 0;
}
