The Last One is the Best (AOJ 0297) by ynu_e
Contest: 3421    RunID: 2277243    Status: Accepted    Date: Sun Apr 23 17:05:38 JST 2017


#include<iostream>

using namespace std;

int Who_Is_winner(int Person, int Stones)
{
  int winner = 0;
  for(;Stones>0;Stones--)
  {
    winner += 1;

    if(winner > Person)
      winner = 1;
  }
  return winner;

}

int main(void)
{
  int Person[100];
  int Stones[100];
  int num =0, winner=0;

  cin>>num;

  for(int i=0;i<num;i++)
    cin>>Stones[i]>>Person[i];

  for(int i=0;i<num;i++)
  {
    winner = Who_Is_winner(Person[i],Stones[i]);
    cout<<winner<<endl;
  }

  return 0;

}