cswork / OAOpen practice workspace

AmazonOA #257

Match Strings (Amazon CN)

Estimated EasyJudge-ready

Topics (AI-labelled)Strings

You are given n pairs of text and pattern. Each pattern contains exactly one *, which can be replaced by zero or more lowercase letters; no other character can be modified. Determine whether each pattern can become the entire corresponding text, and output YES or NO in order. The implementation does not use a built-in regex library.

Input

The first line contains n, followed by n lines each containing text pat, separated by a space. 1≤n≤10, 1≤length of each text and pattern≤100000; texts are lowercase only, and patterns are lowercase apart from the single *.

Output

Output YES or NO on each line, in input order.

Example 1

Input:

2
code co*d
coder co*er

Output:

NO
YES

Example 2

Input:

2
abc ab*bc
abcbc ab*bc

Output:

NO
YES

Example 3

Input:

2
a *
abc abc*

Output:

YES
YES

Example notes

The results are NO/YES, NO/YES and YES/YES. ab*bc needs at least 4 characters; the prefix and the suffix cannot share the same b.

Editorial

Loading solution…