#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) {
    string s, r;
    cin >> s >> r;
    long long n = s.length();
    long long m = r.length();
    if (m < n) {
      cout << "NO";
      cout << "\n";
    } else if (m == n) {
      if (s == r)
        cout << "YES";
      else
        cout << "NO";
      cout << "\n";
    } else {
      bool res = true;
      long long i = 0, j = 0;
      while (i < n && j < m) {
        if (s[i] == r[j]) {
          i++;
          j++;
        } else if (i != 0 && s[i - 1] == r[j]) {
          j++;
        } else {
          res = false;
          break;
        }
      }
      while (j < m) {
        if (j == 0 || r[j] != r[j - 1]) {
          res = false;
          break;
        }
        j++;
      }
      if (i == n && res)
        cout << "YES";
      else
        cout << "NO";
      cout << "\n";
    }
  }
  return 0;
}
