#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s1, s2;
    cin >> s1 >> s2;
    long long ok = 1, i = 0, j = 0;
    long long len1 = s1.length(), len2 = s2.length();
    if (len1 > len2)
      ok = 0;
    else if (s1[0] != s2[0])
      ok = 0;
    else {
      while (i < len1 && j < len2) {
        if (s1[i] == s2[j]) {
          ++i;
          ++j;
        } else {
          if (s2[j] == s2[j - 1])
            j++;
          else {
            ok = 0;
            break;
          }
        }
      }
      if (i != len1 && ok) ok = 0;
      while (j < len2 && ok) {
        if (s2[j] != s1[i - 1]) {
          ok = 0;
        }
        j++;
      }
    }
    if (ok)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}
