#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  cin.ignore();
  while (n--) {
    string str1, str2;
    getline(cin, str1);
    getline(cin, str2);
    bool test = true;
    long long j = 0, i = 0;
    char last_ch = str1[0];
    while (j < str2.size() && i < str1.size()) {
      if (str2[j] == str1[i])
        last_ch = str1[i], i++, j++;
      else if (str2[j] == last_ch) {
        while (str2[j] == last_ch) j++;
      } else {
        test = false;
        break;
      }
    }
    while (j < str2.size()) {
      if (str2[j] != last_ch) {
        test = false;
        break;
      }
      j++;
    }
    if (!test) {
      cout << "NO" << endl;
      continue;
    }
    if (i < str1.size()) {
      cout << "NO" << endl;
      continue;
    }
    cout << "YES" << endl;
  }
  return 0;
}
