Skip to content

UKSPC Practice Problems » Game

In some far away land, the death penalty is legal. The king of the land, who likes to think he is a nice chap, has made the execution of prisoners part of the yearly Games. At the end of the Games, all the prisoners from death row are put in a circle in the arena. One of the prisoners is designated number 1. Then the executioner takes position at the center of the circle, and starts reciting a rhyme he remembers from his childhood: “IENE MIENE MINI NOO, I THINK FOR YOU IT IS TIME TO GO.” For each syllable of the rhyme he aims at a different person, starting with prisoner #1 for 'IENE', prisoner #2 for 'MIENE', etc. Thus with each syllable he moves his aim to the right. The prisoner he aims at with 'GO' is shot, and, while the crowd cheers, is then removed from the scene. At the next recitation of the rhyme, the executioner starts at the rightmost neighbor of the most recently deceased.

The king, being a nice chap, releases the one prisoner left standing at the end of the game.

If you would ever 'participate' in this game, you might want to improve your chances by determining beforehand who is going to be released. To be able to calculate that, you need to know the number of prisoners, and the length in syllables of the rhyme used by the executioner for this particular game. It might be nice to have a program which calculates this quickly for you.

Input Specification

The first line of input contains a single integer N which specifies the number of test cases. Then there are N lines, one per test case, containing two integers each, P and S, where P is the number of prisoners (1 ≤ P ≤ 1,000) and S is the number of syllables in the rhyme (1 ≤ S ≤ 10,000).

Output Specification

For each test case print the following text: 'With P prisoners and S syllables, I'd like to be number X.', where X is the prisoner index of the one surviving (the prisoners are numbered from 1 through P in the direction of the aim of the executioner).

Example Input

3
3 3
6 2
10 1

Example Output

With 3 prisoners and 3 syllables, I'd like to be number 2.
With 6 prisoners and 2 syllables, I'd like to be number 5.
With 10 prisoners and 1 syllables, I'd like to be number 10.