#include <bits/stdc++.h>
using namespace std;
const long long INF = LLONG_MAX;
const long long base = 1e9;
const double PI = acos(-1);
const long long MOD = 1e9 + 7;
const long long N = 1e5 + 10;
long long power(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
void algorithm();
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    string s, t;
    cin >> s >> t;
    vector<pair<char, long long>> v1, v2;
    long long cnt = 1;
    if (s.size() == 1) {
      v1.push_back({s[0], 1});
    } else {
      for (long long i = 0; i < s.size() - 1; i++) {
        if (i == s.size() - 2) {
          if (s[i] == s[i + 1]) {
            v1.push_back({s[i], cnt + 1});
          } else {
            v1.push_back({s[i], cnt});
            v1.push_back({s[i + 1], 1});
          }
        } else {
          if (s[i] == s[i + 1]) {
            cnt++;
          } else {
            v1.push_back({s[i], cnt});
            cnt = 1;
          }
        }
      }
    }
    cnt = 1;
    if (t.size() == 1) {
      v2.push_back({t[0], 1});
    } else {
      for (long long i = 0; i < t.size() - 1; i++) {
        if (i == t.size() - 2) {
          if (t[i] == t[i + 1]) {
            v2.push_back({t[i], cnt + 1});
          } else {
            v2.push_back({t[i], cnt});
            v2.push_back({t[i + 1], 1});
          }
        } else {
          if (t[i] == t[i + 1]) {
            cnt++;
          } else {
            v2.push_back({t[i], cnt});
            cnt = 1;
          }
        }
      }
    }
    long long flag = 0;
    if (v1.size() != v2.size()) {
      cout << "NO\n";
      continue;
    }
    for (long long i = 0; i < v1.size(); i++) {
      if (v1[i].first != v2[i].first) {
        cout << "NO" << endl;
        flag = 1;
        break;
      } else if (v1[i].second > v2[i].second) {
        cout << "NO" << endl;
        flag = 1;
        break;
      }
    }
    if (flag) {
      continue;
    } else {
      cout << "YES\n";
      continue;
    }
  }
}
