QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 512 MB Puntuación total: 100

#14276. Copying Deck

Estadísticas

Bored one day, Little L decided to play the currently popular game "Hearthstone," but he kept losing. He shouted, "I need to copy a deck!" and started watching the stream of Little H, a top-ranked player in the game's Legend division.

However, Little L's internet connection was still at dial-up speeds. The stream was constantly stuttering and glitching, making it impossible for him to record the powerful deck Little H was showcasing. Little L was surrounded by academic high-achievers who didn't play games and weren't interested in helping him, but they were passionate about discussing various informatics problems.

He came up with a method: since the screen glitches occurred at different positions each time, Little H could record different parts of the deck in each instance. If he recorded enough times, couldn't he reconstruct the deck Little L wanted? However, there was one problem: the decks Little H showcased might be different each time, so he wanted to know if the deck fragments he copied from the stream were consistent.

Thus, Little H abstracted his gaming problem into the following academic problem for the high-achievers (you) to solve:

Given $N$ strings containing lowercase English letters, digits, and the wildcard character *, where * can match any sequence of characters of any length (including length 0), determine whether all strings match each other pairwise.

Input

The input file is hs.in. The first line contains a positive integer $T$, representing the number of test cases. Each test case consists of: The first line of each test case is a positive integer $N$, representing the number of strings in that test case. The next $N$ lines each contain a string, consisting only of lowercase letters, digits, and the wildcard *.

Output

The output file is hs.out. The output contains $T$ lines, each containing a letter Y or N. Y indicates that all strings in that test case match each other pairwise, and N indicates that at least one pair of strings in that test case does not match.

Constraints

  • For 10% of the data, $N \le 2$.
  • For 30% of the data, the length of all strings does not exceed 30.
  • For 50% of the data, $N \le 8$.
  • For 70% of the data, $N \le 500$.
  • For 100% of the data, $N \le 100000$, $T = 10$, the input file size does not exceed 10M, and $N \times (\text{maximum string length}) \le 2 \times 10^8$.

Examples

Input 1

3
3
wellplayed
thankyou
pyroblast
2
a*abc
abc*a
2
a*abc
a1234567890abc

Output 1

N
N
Y

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.