#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long power(long long num, long long r) {
  if (r == 0) return 1;
  if (r == 1) return num % mod;
  long long ans = power(num, r / 2) % mod;
  if (r % 2 == 0) {
    return (ans * ans) % mod;
  }
  return (((ans * ans) % mod) * num) % mod;
}
long long modinv(long long num) { return power(num, mod - 2); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    string a, b;
    cin >> a >> b;
    string am, bm;
    vector<int> v1, v2;
    v1.push_back(1);
    v2.push_back(1);
    am += a[0];
    bm += b[0];
    for (int i = 1; i < a.length(); i++) {
      if (a[i] == a[i - 1])
        v1[v1.size() - 1]++;
      else {
        v1.push_back(1);
        am += a[i];
      }
    }
    for (int i = 1; i < b.length(); i++) {
      if (b[i] == b[i - 1])
        v2[v2.size() - 1]++;
      else {
        v2.push_back(1);
        bm += b[i];
      }
    }
    int n1 = v1.size(), n2 = v2.size();
    if (n1 != n2 || am != bm)
      cout << "NO" << endl;
    else {
      int check = 1;
      for (int i = 0; i < n1 && check; i++) {
        if (v1[i] > v2[i]) {
          cout << "NO" << endl;
          check = 0;
        }
      }
      if (check) cout << "YES" << endl;
    }
  }
  return 0;
}
