Under construction

Still being built. Things may change

Snapper Chain (Large)

Time limit5sMemory limit512 MB

Summary
After K snaps on a chain of N toggling snappers, decide whether power reaches the light plugged into the last one.
Level

Medium5 of 10

Topics
Bit manipulation, Math
Solved
No attempts yet

Problem

A Snapper is a small device with an input plug on one side and an output socket on the other. You push the input plug into some output socket, and you plug a light or another device into the Snapper's output socket.

A Snapper that is ON and receiving power passes power to whatever sits in its output socket. A Snapper that is OFF, or that receives no power, passes nothing. When you snap your fingers, every Snapper that is receiving power at that instant flips between ON and OFF.

I bought NN Snappers and chained them together. The first one goes into a wall socket, the second one into the output socket of the first one, and the rest follow the same way. The light is plugged into the NNth Snapper.

All Snappers start OFF, so only the first one receives power and the light is off. One snap turns Snapper 1 ON and power reaches Snapper 2. Two snaps flip both of them, so Snapper 1 goes OFF and the power to Snapper 2 is cut, but Snapper 2 has already flipped to ON and stays ON with no power. Three snaps turn Snapper 1 back ON and power reaches Snapper 2 again. Both are ON now, so a light plugged into Snapper 2 is on.

After KK snaps, is the light on or off? The light is on if and only if it receives power from the Snapper it is plugged into.

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.

  • 1≤T≤100001 \le T \le 10000
  • 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 x is the test case number starting from 1, and y is ON if the light is on and OFF if it is off.

Examples5

  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
    
  3. Example 3

    Input
    8
    2 0
    2 1
    2 2
    2 3
    2 4
    2 5
    2 6
    2 7
    
    Expected output
    Case #1: OFF
    Case #2: OFF
    Case #3: OFF
    Case #4: ON
    Case #5: OFF
    Case #6: OFF
    Case #7: OFF
    Case #8: ON
    
  4. Example 4

    Input
    7
    3 0
    3 6
    3 7
    3 8
    3 14
    3 15
    3 16
    
    Expected output
    Case #1: OFF
    Case #2: OFF
    Case #3: ON
    Case #4: OFF
    Case #5: OFF
    Case #6: ON
    Case #7: OFF
    
  5. Example 5

    Input
    3
    1 0
    15 0
    30 0
    
    Expected output
    Case #1: OFF
    Case #2: OFF
    Case #3: OFF