AirCraft: Monster

AirCraft, the popular aviation video game has released its new version with more monstrous challenges than ever: “AirCraft: Monster”, abbreviated by its fans as ACM. In each successful mission the players will receive an exact amount of experience points (XP), attack points (AP) and defense points (DP), which will accumulate in their profiles. The Missions in ACM doesn’t have a specific order: The player can choose in which order to play them. A mission only gives points the first time it is surpassed, so it is not possible to win points twice with the same mission. ACM awards medals for certain action. The most sought medal is the “Monster Player”. To win this medal, the player must accumulate EXACTLY x experience points, a attack points and d defense points. However, some users have complained, they said that it’s not possible to get exactly these scores with any possible combination of successful missions. Given the x, a and d points needed to win the Monster Player Medal and knowing the XP, AP y DP that every mission awards, is it possible to win the medal, and therefore become a Monster Player? Input Input begins with an integer T , the number of test cases. For each case, the first line contains 4 integers x, a, d and m (1 ≤ x,a,d ≤ 108 and 1 ≤ m ≤ 30), the number of experience points, attack points and defense points needed to win the medal and the number of missions of the game. Then m lines come, each one describing a mission of ACM. A mission consist of a string s (s containing no white spaces), the name of the mission, and 3 integers XP, AP and DP (1 ≤ XP,AP,DP ≤ 107), the points that the mission awards. Output For each test case prints a line containing ‘POSSIBLE’ if its possible to become a Monster Player, or ‘IMPOSSIBLE’ if there is no way to achieve the medal. Sample Input 2 100 100 100 5 MISSION1 30 10 40 MISSION2 40 70 30 MISSION3 40 10 20 MISSION4 20 20 50 MISSION5 10 50 90 100 100 100 3 a 10 30 10 b 10 10 40 c 10 60 50 Sample Output POSSIBLE IMPOSSIBLE