#include <bits/stdc++.h>
using namespace std;
const int MAX = 100 + 2, MOD = 100000007;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc;
  cin >> tc;
  for (int nc = 1; nc <= tc; nc++) {
    string s1, s2;
    cin >> s1 >> s2;
    int n1, n2;
    n1 = (int)s1.size();
    n2 = (int)s2.size();
    if (n2 < n1 || s1[0] != s2[0]) {
      cout << "NO\n";
      continue;
    }
    int i, j;
    char prv;
    for (i = 0, j = 0; i < n1 && j < n2; i++) {
      if (s2[j] == s1[i]) {
        j++;
        prv = s1[i];
        continue;
      }
      while (j < n2 && s2[j] == prv) j++;
      if (j >= n2 || s2[j] != s1[i]) break;
      i--;
    }
    while (j < n2) {
      if (s2[j] == s1[n1 - 1])
        j++;
      else
        break;
    }
    if (i >= n1 && j >= n2) {
      cout << "YES\n";
    } else
      cout << "NO\n";
  }
  return 0;
}
