#K80782. Validate Trading Card Game Trades

    ID: 35607 Type: Default 1000ms 256MiB

Validate Trading Card Game Trades

Validate Trading Card Game Trades

You are given TT test cases. Each test case describes a series of trades in a trading card game. Initially, there are nn different types of cards, and you are provided with an array of nn integers, where the ithi^{th} integer represents the number of cards of type ii. Following that, you will perform mm trades. Each trade is given by four integers (a,b,c,d)(a, b, c, d), meaning that you trade cc cards of type aa to receive dd cards of type bb. A trade is valid only if, at the time of the trade, you have at least cc cards of type aa. If any trade is invalid, then the entire test case is marked as "Invalid"; otherwise, it is "Valid".

Your task is to determine for each test case whether the sequence of trades is valid.

inputFormat

The input is given via standard input (stdin) and has the following format:

  • The first line contains an integer TT, representing the number of test cases.
  • For each test case:
    • The first line contains two integers nn and mm, where nn is the number of card types and mm is the number of trades.
    • The second line contains nn space-separated integers, representing the initial count of each card type.
    • Each of the next mm lines contains four space-separated integers: aa, bb, cc, dd, describing a trade as explained above.

All input is read from stdin.

outputFormat

For each test case, output a single line to standard output (stdout) containing either "Valid" or "Invalid" based on whether the sequence of trades is valid.## sample

3
3 3
5 10 5
1 2 4 3
3 1 2 2
2 3 1 1
2 2
3 5
1 2 4 6
2 1 3 5
2 1
5 5
1 2 2 2
Valid

Invalid Valid

</p>