KCM Travel

No attempts yetTime limit3sMemory limit256 MB

Problem

Chanmin qualified for Google Code Jam World Finals, but Google pays at most MM for travel. Given flights with cost and duration between airports, find the minimum travel time from airport 1 (Incheon) to airport NN (LA) with total cost at most MM. If impossible, print Poor KCM.

Input

  • Line 1: integer TT (always 1)
  • Per test: integers NN, MM, KK, then KK lines with uu, vv, cc, dd

Output

For each test, print the minimum time, or Poor KCM if no route fits the budget.