#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b) { return (a > b ? a : b); }
long long min(long long a, long long b) { return (a < b ? a : b); }
void algo() {
  string s1, s2;
  char c;
  cin >> s1 >> s2;
  long long j = 0, len = s1.size();
  for (long long i = 0; i < len; i++) {
    c = s1[i];
    long long k = j;
    if (s1[i + 1] == c && i != len - 1) {
      if (c == s2[j])
        j++;
      else {
        cout << "NO";
        return;
      }
    } else {
      while (c == s2[j]) {
        j++;
      }
    }
    if (k == j) {
      cout << "NO";
      return;
    }
  }
  if (j != s2.size())
    cout << "NO";
  else
    cout << "YES";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    algo();
    cout << endl;
  }
  return 0;
}
