#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    string a, b;
    cin >> a >> b;
    if (b.size() < a.size()) {
      cout << "NO";
    } else {
      long long int flag = 0, i, j;
      for (i = 0, j = 0; i < a.size();) {
        if (a[i] == b[j]) {
          i++;
          j++;
        } else if (b[j] == a[i - 1]) {
          j++;
        } else {
          flag = 1;
          break;
        }
      }
      for (int z = j; z < b.size(); z++) {
        if (b[z] != a[i - 1]) {
          flag = 1;
          break;
        }
      }
      if (flag) {
        cout << "NO";
      } else {
        cout << "YES";
      }
    }
    cout << endl;
  }
}
