// Arup Guha
// Solution to UF Contest Question: DNA Compression
// 1/30/2010

import java.util.*;

// Manages a simple pair which is part of a sequence of DNA.
class pair {
	
	public int num;
	public char c;
	
	public pair(int n, char ch) {
		num = n;
		c = ch;
	}
	
	public boolean equals(pair p) {
		return c == p.c && num == p.num;
	}
}

public class dna {
	
	public static void main(String[] args) {
		
		Scanner stdin = new Scanner(System.in);
		
		int numCases = stdin.nextInt();
		
		// Go through each case.
		for (int i=0; i<numCases; i++) {
			
			// Read in both strings.
			String orig = stdin.next();
			String compressed = stdin.next();
			
			// Convert to our array list of pairs form.
			ArrayList<pair> first = compress(orig);
			ArrayList<pair> other = convert(compressed);
			
			// Output the answer.
			if (equals(first, other))
				System.out.println("Yes");
			else
				System.out.println("No");
		}
	}
	
	// Compresses a regular DNA string and returns its representation
	// as an array list of pairs.
	public static ArrayList<pair> compress(String orig) {
		
		char[] letters = orig.toCharArray();
		
		ArrayList<pair> list = new ArrayList<pair>();
		
		int cnt=0;
		char let = letters[0];
		int index = 0;
		
		// Go through the whole string.
		while (index < letters.length) {
			
			// Find all the same letters.
			while (index < letters.length && let == letters[index]) {
				cnt++;
				index++;
			}
			
			// This encodes this run of letters.
			list.add(new pair(cnt, let));
			
			// Avoid array out of bounds.
			if (index == letters.length) break;
			
			// Advances to the next letter.
			let = letters[index];
			cnt = 0;
			
		}
		
		return list;
	}
	
	// Converts a already coded string into our representation.
	public static ArrayList<pair> convert(String code) {
		
		int index = 0;
		ArrayList<pair> list = new ArrayList<pair>();
		
		// Go through the string.
		while (index < code.length()) {
			
			// Interpret the value of the number.
			int val = 0;
			char c = code.charAt(index);
			while ('0' <= c && c <= '9') {
				val = 10*val + (c - '0');
				index++;
				c = code.charAt(index);
			}
			
			// Case where the optional 1 wasn't added.
			if (val == 0) val = 1;
			
			// Now we can add this character, which is sure to
			// be the letter.
			list.add(new pair(val, c));
			
			// Move onto the next letter. (Well it'll prob. be a number.)
			index++;
		}
		
		return list;
	}
	
	// Returns true if a and b are encoding equal DNA strings.
	public static boolean equals(ArrayList<pair> a, ArrayList<pair> b) {
		
		// The number of runs must be equal.
		if (a.size() != b.size())
			return false;
		
		// If any corresponding pair isn't equal, the sequences aren't either.
		for (int i=0; i<a.size(); i++)
			if (!(a.get(i).equals(b.get(i))))
				return false;
				
		// a and b must be equal if we get here.
		return true;
	}
	
}