Wormly

Time limit1sMemory limit128 MB

Summary
Find the minimum number of moves to shift a worm's body window and its ordered legs across a bridge with missing planks, or report impossibility.
Level

Hard8 of 10

Topics
Greedy, Two pointers, Simulation
Solved
No attempts yet

Problem

Jonly is making his first computer game. In the opening scene the hero, Wormly, has to cross the bridge Bridgely.

Wormly is a worm made of bb identical round bubbles and ll legs. At every instant each leg must be directly below one of the bubbles, and each bubble may have at most one leg below it. The bubbles touch one another, so the bb bubbles always cover bb consecutive planks.

Bridgely consists of nn planks, each as wide as one bubble, but some planks are missing. A leg may rest only on an existing plank, never on a gap.

At each step Wormly performs exactly one of the following actions:

  • Move one leg forward over any number of planks (existing or missing). After the move the leg must rest on an existing plank that lies below one of the bubbles. A leg may never pass another leg, so the legs keep their left-to-right order.
  • Move every bubble forward by one plank while all legs stay on their current planks. After this move each leg must still be below some bubble.

Initially the bubbles cover the leftmost bb planks and the legs rest on the leftmost ll planks. The animation ends when the bubbles cover the rightmost bb planks and the legs rest on the rightmost ll planks. The leftmost ll planks and the rightmost ll planks are guaranteed to exist.

Determine the minimum number of steps Wormly needs to cross, counting both leg moves and bubble moves, or report that crossing is impossible.

Input

The first line contains a positive integer TT, the number of test cases (T≤100T \le 100). Each test case consists of two lines:

  • A line with three integers ll, bb and nn (1≤l≤b≤n≤1061 \le l \le b \le n \le 10^6): the number of legs, the number of bubbles, and the number of planks.
  • A line with a string of nn characters, each either 1 or 0. A 1 marks an existing plank and a 0 marks a missing plank.

Output

For each test case output a single line with one integer: the minimum number of steps Wormly needs to cross the bridge. If crossing is impossible, output IMPOSSIBLE instead.

Examples3

  1. Example 1

    Input
    3
    1 2 2
    11
    2 3 5
    11011
    1 3 5
    11011
    
    Expected output
    1
    IMPOSSIBLE
    5
    
  2. Example 2

    Input
    4
    2 2 2
    11
    1 1 1
    1
    1 3 3
    111
    2 3 3
    111
    
    Expected output
    0
    0
    1
    2
    
  3. Example 3

    Input
    3
    2 2 3
    111
    3 3 5
    11111
    1 1 4
    1111
    
    Expected output
    IMPOSSIBLE
    IMPOSSIBLE
    IMPOSSIBLE