#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e18 + 7;
const double tiaohe = 0.57721566490153286060651209;
long long oula(long long x) {
  long long res = x;
  for (register int i = 2; i <= x / i; ++i) {
    if (x % i == 0) {
      res = res / i * (i - 1);
      while (x % i == 0) x /= i;
    }
  }
  if (x > 1) res = res / x * (x - 1);
  return res;
}
long long quickmod(long long a, long long n, long long m) {
  long long s = 1;
  while (n) {
    if (n & 1) {
      s = s * a % m;
    }
    a = (a * a) % m;
    n = n / 2;
  }
  return s;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
void ex_gcd(long long a, long long b, long long &x, long long &y,
            long long &d) {
  if (!b) {
    d = a, x = 1, y = 0;
  } else {
    ex_gcd(b, a % b, y, x, d);
    y -= x * (a / b);
  }
}
long long inv(long long t, long long p) {
  long long d, x, y;
  ex_gcd(t, p, x, y, d);
  return d == 1 ? (x % p + p) % p : -1;
}
bool isPrime(long long x) {
  if (x == 2) return true;
  if (x % 2 == 0) return false;
  for (long long i = 2; i * i <= x; i++)
    if (x % i == 0) return false;
  return true;
}
const int N = 1e6 + 5;
int t;
struct node {
  char x;
  int y;
} a[N], b[N];
int cnt1, cnt2;
int main() {
  cin >> t;
  string s1, s2;
  while (t--) {
    cin >> s1 >> s2;
    cnt1 = 0, cnt2 = 0;
    a[++cnt1] = {s1[0], 1};
    b[++cnt2] = {s2[0], 1};
    int tt = s1.size() - 1, kk = s2.size() - 1;
    for (register int i = 1; i <= tt; ++i) {
      if (s1[i] == s1[i - 1])
        a[cnt1].y++;
      else
        a[++cnt1] = {s1[i], 1};
    }
    for (register int i = 1; i <= kk; ++i) {
      if (s2[i] == s2[i - 1])
        b[cnt2].y++;
      else
        b[++cnt2] = {s2[i], 1};
    }
    if (cnt1 == cnt2) {
      int fg = 0;
      for (register int i = 1; i <= cnt1; ++i) {
        if (a[i].x != b[i].x || a[i].y > b[i].y) {
          fg = 1;
          break;
        }
      }
      if (fg)
        puts("NO");
      else
        puts("YES");
    } else
      puts("NO");
  }
  return 0;
}
