Cables ... in Spaaace!

Time limit1sMemory limit128 MB

Summary
Given a planet's diameter and up to 100 city coordinates, compute the minimum cable length of a strongly connected network and compare it to the available length L.
Level

Medium6 of 10

Topics
Graph, Minimum spanning tree, Geometry, Math
Solved
No attempts yet

Problem

You are writing a science fiction novel. In your story, humanity has spread throughout the galaxy and colonized many planets. Apart from interstellar travel, you keep every other technology — computers especially — close to what exists in today's world. So the computer networks on those colonized planets are still built by running copper or fiber-optic cable between the computers.

Modern computer networks use packet switching, so you do not have to run a separate cable between every pair of computers. It is enough for the network to remain strongly connected: for every pair of computers, there must exist at least one path (possibly forwarded through any number of intermediate computers) along which packets can travel in both directions.

This property lets you minimize the total length of cable needed so that every computer can still communicate with every other. For your newly colonized planet, you want to know the minimum total cable length required to connect all of its cities, with no redundant or aggregate links.

For the calculation, assume that:

  • the planet is a perfect sphere;
  • every cable is laid along the planet's surface (a great-circle arc);
  • no surface obstructions (rivers, mountain ranges, etc.) impede the cable.

The input gives the planet's diameter and the cities' coordinates as latitude and longitude in degrees. Latitude ranges from −90∘-90^\circ at the South pole to +90∘+90^\circ at the North pole, with 0∘0^\circ at the equator. Longitude ranges from −180∘-180^\circ to +180∘+180^\circ, with 0∘0^\circ at the prime meridian; by convention, negative longitude is west of the prime meridian and positive longitude is east.

Given the available cable length LL, decide whether it is enough to connect all the cities.

Input

The first line contains a single integer NN (1≤N≤1001 \le N \le 100), the number of data sets. Each data set consists of:

  • one line with a decimal number DD (1≤D≤1,000,0001 \le D \le 1{,}000{,}000), the diameter of the planet in kilometers;
  • one line with a decimal number LL (1≤L≤1,000,0001 \le L \le 1{,}000{,}000), the total length of cable in kilometers available to build the network;
  • one line with a single integer CC (1≤C≤1001 \le C \le 100), the number of cities on the planet;
  • then CC lines, each containing two decimal numbers "X YX\ Y" giving the latitude and longitude (both in degrees) of one city, where −90≤X≤90-90 \le X \le 90 and −180≤Y≤180-180 \le Y \le 180.

Output

For each data set, print a single line. Print IS POSSIBLE if the available cable length LL is enough to network all the cities, or IS NOT POSSIBLE if the cable is too short.

Examples1

  1. Example 1

    Input
    2
    12742
    5900
    3
    51.3 0
    42.5 -75
    48.8 3
    12742
    620
    2
    30.266 97.75
    30.45 91.1333
    
    Expected output
    IS POSSIBLE
    IS NOT POSSIBLE