#include <bits/stdc++.h>
using namespace std;
int main() {
  long int n;
  cin >> n;
  for (int k = 0; k < n; k++) {
    string s1, s2;
    cin >> s1 >> s2;
    long int i = 0, j = 0, p = 0;
    while (i < s1.size() && j < s2.size()) {
      if (s1[i] == s2[j]) {
        i++;
        j++;
      } else {
        if (i > 0 && s1[i - 1] == s2[j])
          j++;
        else {
          cout << "NO" << endl;
          p = 1;
          break;
        }
      }
    }
    if (p == 1)
      continue;
    else if (i < s1.size())
      cout << "NO" << endl;
    else {
      while (j < s2.size()) {
        if (s2[j] != s1[s1.size() - 1]) {
          cout << "NO" << endl;
          break;
        }
        j++;
      }
      if (j == s2.size()) cout << "YES" << endl;
    }
  }
}
