IKRI - Ikri Bikri

Poltu likes a lot his own game ‘Ikri Bikri’. It’s a string related game made by himself. In this game at first he takes a string. Suppose the string is:

Here, the first row denotes the string and 2nd row denotes the indices of every characters.

According to rules of ‘Ikri Bikri’, he has to choose a character from the given string. He chose ‘z’, and the index of ‘z’ is 9. Now, Poltu has to find the index number after reversing it. He found the answer ‘3’.

But what will happen if we choose character ‘a’? There are two a’s in the string. So it’s confusing. That’s why we changed the formula of this game.

Now you will be given an index number N rather than its value. Find out the new index number of N’s value after reversing it.

Poltu knows coding a little bit. He knows the first index of any string is 0 and the last index of the string is len-1, where len is the length of that string. To solve this problem he puts all indices number from 0 to len-1 to an integer array. Then he reversely copies it into another array. After that he finds the answer. He wrote this code:

int main()
{
    int ind = 0;
    int len = 13;
    int N = 9;
    int arr1[100], arr2[100], ans;

    for(int i = 0; i < len; i++)
    {
        arr1[i] = i; //assign index numbers to an array
    }

    for(int i = len-1; i > = 0; i--)
    {
        arr2[ind++] = arr1[i]; //reversely copy the index numbers into another array
    }

    for(int i = 0; i < len; i++)
    {
        if(arr2[i]==N)
        {
            ans = i;
            break;
        }
    }
    printf("%d", ans);
    return 0;
}

This code works for only one input. You have to rewrite it according to input/output format those are given below.

Input

First line of input file contains an integer T (0 <= T <= 100000). T denotes the number of test cases. Then T lines of input set will be available. Every line contains two integers L (1 <= L <= 2^32) and N (0 <= N < L). Where L is the length of string and N is the index number of chosen character (from 1st string before reverse).

Output

Print case number and the output. See sample for clear understanding.

Sample

Input:
3
13 9
13 7
13 6

Output:
Case 1: 3
Case 2: 5
Case 3: 6

Added by:Rofi
Date:2016-07-22
Time limit:0.5s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 GOSU

© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.