#include <bits/stdc++.h>
const long long MX = 1e18, N = 1e5;
const double PI = 3.141592653589793238;
using namespace std;
long long t, n;
string s2, s;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> t;
  while (t--) {
    int cnt = 1, ok = 1;
    deque<char> dq;
    cin >> s >> s2;
    s += '#';
    for (int i = 0; i < s2.size(); ++i) dq.push_back(s2[i]);
    for (int i = 0; i < s.size() - 1; ++i) {
      if (s[i] == s[i + 1])
        cnt++;
      else {
        while (dq.size() && dq.front() == s[i]) dq.pop_front(), cnt--;
        if (cnt > 0) ok = 0;
        cnt = 1;
      }
    }
    cout << (ok && dq.empty() ? "YES\n" : "NO\n");
  }
  return 0;
}
