#include <bits/stdc++.h>
using namespace std;
signed main() {
  int n;
  cin >> n;
  for (int t = 0; t < n; t++) {
    string s;
    cin >> s;
    string s1;
    cin >> s1;
    int t1 = 1;
    bool z = 0;
    if (s1[0] != s[0]) {
      z = 1;
    }
    for (int q = 1; q < s.size(); q++) {
      if (t1 == s1.size()) {
        z = 1;
        break;
      }
      while (s[q] != s1[t1]) {
        if (s1[t1] != s1[t1 - 1]) {
          z = 1;
          break;
        }
        t1++;
        if (t1 == s1.size()) {
          z = 1;
          break;
        }
      }
      t1++;
    }
    for (int r = t1; r < s1.size(); r++) {
      if (s1[r] != s1[r - 1]) {
        z = 1;
        break;
      }
    }
    if (z) {
      cout << "NO" << endl;
    }
    if (!z) {
      cout << "YES" << endl;
    }
  }
}
