#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int flag = 0;
  int C1, C2;
  int i, j;
  char s1[1000005], s2[1000005];
  memset(s1, 0, 1000005);
  memset(s2, 0, 1000005);
  cin >> n;
  while (n--) {
    flag = 0;
    cin >> s1 >> s2;
    if (strcmp(s1, s2) == 0) {
      cout << "YES" << endl;
      continue;
    }
    for (i = 0, j = 0;;) {
      C1 = 0, C2 = 0;
      if (s1[i] == '\0' && s2[j] == '\0') {
        flag = 0;
        break;
      } else if (s1[i] == '\0' || s2[i] == '\0') {
        flag = 1;
        break;
      }
      while (s1[i] == s1[i + 1]) {
        i++, C1++;
      }
      while (s2[j] == s2[j + 1]) {
        j++, C2++;
      }
      if (s1[i++] != s2[j++] || C1 > C2) {
        flag = 1;
        break;
      }
    }
    if (flag)
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
    memset(s1, 0, strlen(s1));
    memset(s2, 0, strlen(s2));
  }
  return 0;
}
