#include <iostream>
using namespace std;
const int N=1e6+10;
int a[N];
void SolveJosephus(int n,int r,int k)
{
for(int i=0;i<n;i++) a[i]=i;
int cur=r-1;
while(n>1)
{
cur=(cur+k-1)%n;
for(int i=cur;i<n-1;i++) a[i]=a[i+1];
n--;
}
cout<<a[0]+1<<endl;
}
int main()
{
int T;
cin>>T;
while(T--)
{
int n,r,k;
cin>>n>>r>>k;
SolveJosephus(n,r,k);
}
return 0;
}
#include <iostream>
#include <cstdlib>
using namespace std;
typedef struct node
{
int number;
struct node *next;
}Node;
Node *CreateList(int n)
{
Node *head=NULL,*tail;
for(int i=1;i<=n;i++)
{
Node *p=(Node *)malloc(sizeof(Node));
p->number=i;
p->next=NULL;
if(head==NULL) head=p;
else tail->next=p;
tail=p;
}
tail->next=head;
tail=head;
return head;
}
void SolveJosephus(Node *head,int n,int r,int k)
{
int i=1;
Node *p=head;
while(i<r)
{
p=p->next;
i++;
}
while(p->next!=p)
{
for(i=1;i<k-1;i++) p=p->next;
Node *temp=p->next;
p->next=temp->next;
p=p->next;
free(temp);
}
cout<<p->number<<endl;
}
int main()
{
int T;
cin>>T;
while(T--)
{
int n,r,k;
cin>>n>>r>>k;
if(k==1)
{
cout<<(r==1 ? n:r-1)<<endl;
continue;
}
Node *head=CreateList(n);
SolveJosephus(head,n,r,k);
}
return 0;
}
#include <iostream>
#include <list>
using namespace std;
void SolveJosephus(int n,int r,int k)
{
list<int>a;
for(int i=1;i<=n;i++) a.push_back(i);
list<int>::iterator it=a.begin();
for(int i=1;i<r;i++) it++;
while(a.size()>1)
{
for(int i=1;i<k;i++)
{
if(it==a.end()) it=a.begin();
it++;
}
if(it==a.end()) it=a.begin();
it=a.erase(it);
if(it==a.end()) it=a.begin();
}
cout<<*it<<endl;
}
int main()
{
int T;
cin>>T;
while(T--)
{
int n,r,k;
cin>>n>>r>>k;
SolveJosephus(n,r,k);
}
return 0;
}
#include <iostream>
#include <vector>
using namespace std;
void SolveJosephus(int n,int r,int k)
{
vector<int>a;
for(int i=0;i<n;i++) a.push_back(i+1);
int cur=r-1;
while(a.size())
{
cur=(cur+k-1)%a.size();
a.erase(a.begin()+cur);
}
cout<<a[cur]<<endl;
}
int main()
{
int T;
cin>>T;
while(T--)
{
int n,r,k;
cin>>n>>r>>k;
SolveJosephus(n,r,k);
}
return 0;
}