#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string a, b;
    cin >> a >> b;
    int r = 0;
    char flag = '.';
    bool res = 1;
    for (int i = 0; i < a.size();) {
      if (r >= b.size()) {
        res = 0;
        break;
      }
      if (a[i] == b[r])
        flag = a[i], r++, i++;
      else if (b[r] == flag)
        r++;
      else {
        res = 0;
        break;
      }
    }
    while (r < b.size()) {
      if (b[r] == flag)
        r++;
      else {
        res = 0;
        break;
      }
    }
    cout << (res ? "YES" : "NO") << endl;
  }
  return 0;
}
