#include <bits/stdc++.h>

using namespace std;

void solve() {
	
	string a, b;
	
	cin >> a >> b;
	
	if(a.length() > b.length() || 2 * a.length() < b.length() || a[0] != b[0]) {
		
		cout << "NO" << endl;
		
		return ;
		
	}
	
	vector<int> a_count, b_count;
	
	int count = 1;
	
	for(int i = 1; i < a.length(); i++) {
		
		if(a[i] != a[i - 1]) {
			
			a_count.push_back(count);
			
			count = 1;
			
		}
		
		else {
			
			count++;
			
		}
		
	}
	
	a_count.push_back(count);
	
	count = 1;
	
	for(int i = 1; i < b.length(); i++) {
		
		if(b[i] != b[i - 1]) {
			
			b_count.push_back(count);
			
			count = 1;
			
		}
		
		else {
			
			count++;
			
		}
		
	}
	
	b_count.push_back(count);
	
	if(a_count.size() != b_count.size()) {
		
		cout << "NO" << endl;
		
		return ;
		
	}
	
	for(int i = 0; i < a_count.size(); i++) {
		
		if(a_count[i] > b_count[i] || 2 * a_count[i] < b_count[i]) {
			
			cout << "NO" << endl;
			
			return ;
			
		}
		
	}
	
	cout << "YES" << endl;
	
}

int main() {
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int t;
	
	cin >> t;
	
	while(t--) {
		
		solve();
		
	}
	
	return 0;
	
}