#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  string s1, s2;
  while (n--) {
    cin >> s1 >> s2;
    int cs = 0, i = 0, j = 0, cj = 0, f = 0;
    char prev = (char)95;
    if (s2.size() < s1.size())
      f = 1;
    else {
      while (i < s1.size() && j < s2.size()) {
        if (s1[i] == s2[j]) {
          prev = s1[i];
          i++;
          j++;
        } else if (s2[j] == prev)
          j++;
        else {
          f = 1;
          break;
        }
      }
      if (i < s1.size()) f = 1;
      while (j < s2.size()) {
        if (s2[j] == prev)
          j++;
        else {
          f = 1;
          break;
        }
      }
    }
    if (f == 0)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
