#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1);
const long long mod = 1e9 + 7;
const long double eps = 1e-9;
const int maxn = 1e5 + 10;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
vector<pair<char, int> > vp1;
vector<pair<char, int> > vp2;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    vp1.clear();
    vp2.clear();
    string s1, s2;
    cin >> s1 >> s2;
    int len1 = s1.length(), len2 = s2.length();
    char temp = s1[0];
    for (int i = 0; i < len1;) {
      if (s1[i] == temp) {
        int cnt = 0;
        while (s1[i] == temp) {
          i++;
          cnt++;
        }
        pair<char, int> pp = make_pair(temp, cnt);
        vp1.push_back(pp);
        temp = s1[i];
      }
    }
    temp = s2[0];
    for (int i = 0; i < len2;) {
      if (s2[i] == temp) {
        int cnt = 0;
        while (s2[i] == temp) {
          i++;
          cnt++;
        }
        pair<char, int> pp = make_pair(temp, cnt);
        vp2.push_back(pp);
        temp = s2[i];
      }
    }
    int sz1 = vp1.size(), sz2 = vp2.size();
    if (sz1 != sz2) {
      cout << "NO" << endl;
    } else {
      int flag = 1;
      for (int i = 0; i < sz1; i++) {
        if (vp1[i].first != vp2[i].first) {
          flag = 0;
          break;
        } else if (vp1[i].second > vp2[i].second) {
          flag = 0;
          break;
        }
      }
      if (flag)
        cout << "YES" << endl;
      else
        cout << "NO" << endl;
    }
  }
  return 0;
}
