#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
using namespace std;
int n;
void Move(int x,int z);
int main()
{
int s;
scanf("%d",&s);
n=0;
while(s--)
{
int m,p;
scanf("%d",&m);
scanf("%d",&p);
n++;
Move(m,p);
}
}
void Move(int x,int z)
{
int j,k;
j=0;
k=0;
int pos[100], live[100];
int start;
memset(pos,0,sizeof(pos));
for(int i=1;i<=x;i++)
{
pos[i]=i;
}
start=1;
while(j < x)
{
while(start <= x)
{
if(pos[start] !=0)
k++;
if(k == z)
{
live[j]=pos[start];
pos[start]=0;
j++;
k=0;
}
start++;
}
start=1;
}
printf("Case %d :",n);
printf("%d\n",live[x-1]);
}
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
using namespace std;
int n;
void Move(int x,int z);
int main()
{
int s;
scanf("%d",&s);
n=0;
while(s--)
{
int m,p;
scanf("%d",&m);
scanf("%d",&p);
n++;
Move(m,p);
}
}
void Move(int x,int z)
{
int j,k;
j=0;
k=0;
int pos[100], live[100];
int start;
memset(pos,0,sizeof(pos));
for(int i=1;i<=x;i++)
{
pos[i]=i;
}
start=1;
while(j < x)
{
while(start <= x)
{
if(pos[start] !=0)
k++;
if(k == z)
{
live[j]=pos[start];
pos[start]=0;
j++;
k=0;
}
start++;
}
start=1;
}
printf("Case %d :",n);
printf("%d\n",live[x-1]);
}