TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

Jenny has two lists of integers, namely a_1,...,a_N and b_1,...,b_M. Jeffrey wants to know what these numbers are, but Jenny won't tell him the numbers directly. So, Jeffrey asks Jenny a series of questions of the form "How big is a_i + b_j?" Jenny won't even tell him that, though; instead, she answers either "It's at least c," or "It's at most c." (Right, Jenny simply doesn't want to give his numbers for whatever reason.) After getting Jenny's responses, Jeffrey tries to guess the numbers, but he cannot figure them out no matter how hard he tries. He starts to wonder if Jenny has lied while answering some of the questions. Write a program to help Jeffrey.

Input Format

The first line of the input file contains an integer T, which is the number of test cases.

Each test case begins with a line containing three positive integers N, M, and Q, which denote the lengths of the Jenny's lists and the number of questions that Jeffrey asked. These numbers satisfy 2<=N+M<=1000 and 1<=Q<=10000. Each of the next Q lines is of the form "i j <= c" or "i j >= c". The former represents a_i + b_j<= c, and the latter represents a_i + b_j>= c. It is guaranteed that -1000<= c<= 1000.

Output Format

For each test case, print a single line that contains "Possible" if there exist integers a_1,...,a_N and b_1,...,b_M that are consistent with Jenny's answers,
or "Impossible" if it can be proven that Jenny has definitely lied (quotes added for clarity).

Sample Input 1

2
2 1 3
1 1 &lt;= 3
2 1 &lt;= 5
1 1 &gt;= 4
2 2 4
1 1 &lt;= 3
2 1 &lt;= 4
1 2 &gt;= 5
2 2 &gt;= 7

Sample Output 1

Impossible
Possible

Hints

Problem Source

Migrated from old NTUJ.

2011 Stanford Local

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 5000 65536 200