#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long i, j = 0, n;
  string s1, s2;
  cin >> n;
  while (n--) {
    cin >> s2 >> s1;
    j = 0;
    for (i = 0; i < s2.size() && j < s1.size(); i++) {
      if (s1[j] == s2[i]) {
        j++;
        if (i == s2.size() - 1) {
          while (j < s1.size() && s1[j] == s2[i]) j++;
        }
      } else {
        if (j >= 0 && s1[j] == s1[j - 1]) {
          j++;
          i--;
        } else
          break;
      }
    }
    if (i == s2.size() && j == s1.size())
      cout << "YES\n";
    else
      cout << "NO\n";
  }
}
