#K7536. Document State Transition Validator
Document State Transition Validator
Document State Transition Validator
You are given a sequence of state transitions for a document. The document processing follows strictly defined rules:
- The document must start with the state (\texttt{Created}).
- After (\texttt{Created}), the document can only transition to (\texttt{Opened}).
- From (\texttt{Opened}), it can transition to either (\texttt{Modified}) or (\texttt{Saved}).
- If the document is (\texttt{Modified}), the next valid state is only (\texttt{Saved}).
- From (\texttt{Saved}), the document can be either (\texttt{Closed}) or (\texttt{Archived}).
- The states (\texttt{Closed}) and (\texttt{Archived}) are terminal; no further transitions are allowed after reaching them.
For each test case, determine whether the given sequence of transitions is valid according to these rules. Output "Valid" if the sequence is correct or "Invalid" if any rule is violated.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains an integer (T) representing the number of test cases.
- For each test case, the first line contains an integer (n) representing the number of transitions. The next line contains (n) space-separated strings, each representing a state in the sequence.
Example: 5 5 Created Opened Modified Saved Closed 5 Created Opened Saved Archived Modified 3 Created Saved Closed 4 Created Opened Saved Closed 6 Created Opened Modified Saved Archived
outputFormat
For each test case, print a single line with either "Valid" if the sequence of transitions adheres to the rules, or "Invalid" if it does not. The output should be written to standard output (stdout).
Example output for the sample input: Valid Invalid Invalid Valid Valid## sample
5
5
Created Opened Modified Saved Closed
5
Created Opened Saved Archived Modified
3
Created Saved Closed
4
Created Opened Saved Closed
6
Created Opened Modified Saved Archived
Valid
Invalid
Invalid
Valid
Valid
</p>