Under construction

Still being built. Things may change

Snapper Chain (Large)

Time limit5sMemory limit512 MB

Summary
You daisy-chain N snappers that toggle when powered and report whether the bulb at the end is lit after K snaps.
Level

Medium4 of 10

Topics
Bit manipulation, Math
Solved
No attempts yet

Problem

A snapper is a small electrical device with an input plug on one side and an output socket on the other. You can plug an appliance such as a light bulb into the output socket, or the input plug of another snapper.

A snapper is either ON or OFF. Power leaves the output socket only when the snapper is ON and its input plug is receiving power. When you snap your fingers, every snapper that is receiving power at that moment reacts to the sound and flips between ON and OFF.

One day I bought NN snappers. I plugged the input plug of the first snapper into a power socket, plugged the input plug of the second snapper into the output socket of the first, and continued that way down the chain. Then I attached a light bulb to the output socket of the NNth snapper.

At the start every snapper is OFF, only the first snapper receives power, and the bulb is dark. After one snap the first snapper turns ON and power reaches the second snapper. After a second snap the first and second snappers both flip, so the second snapper is ON but receives no power. On the third snap only the first snapper flips, and now the first and second are both ON. If a bulb were attached to the output socket of the second snapper, it would light up.

I kept snapping my fingers for hours. After KK snaps, is the bulb lit? The bulb is an ordinary one with no tricks in it, and it shines only while the snapper in front of it supplies power.

Input

The first line contains the number of test cases TT. Each of the next TT lines contains two integers NN and KK separated by a space.

Constraints

  • 1≤T≤50001 \le T \le 5000
  • 1≤N≤301 \le N \le 30
  • 0≤K≤1080 \le K \le 10^8

Output

For each test case print one line in the form Case #X: Y. Here XX is the test case number starting from 1, and YY is ON if the bulb is lit after KK snaps and OFF otherwise.

Examples2

  1. Example 1

    Input
    4
    1 0
    1 1
    4 0
    4 47
    
    Expected output
    Case #1: OFF
    Case #2: ON
    Case #3: OFF
    Case #4: ON
    
  2. Example 2

    Input
    6
    1 0
    1 1
    1 2
    1 3
    1 4
    1 5
    
    Expected output
    Case #1: OFF
    Case #2: ON
    Case #3: OFF
    Case #4: ON
    Case #5: OFF
    Case #6: ON