The Last One is the Best (AOJ 0297) by ynu_c
Contest: 3421    RunID: 2277095    Status: Accepted    Date: Sun Apr 23 15:55:30 JST 2017


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int k1[n],k2[n];
    for(int i=0;i<n;i++){
        cin>>k1[i]>>k2[i];
        int ans=k1[i]%k2[i];
        if(ans==0){
            cout<<k2[i]<<endl;
        }
        else{
            cout<<ans<<endl;
        }
    }
        return 0;
}