The Last One is the Best (AOJ 0297) by ynu_d
Contest: 3421    RunID: 2277090    Status: Accepted    Date: Sun Apr 23 15:50:49 JST 2017


#include <bits/stdc++.h>
#include<algorithm>
using namespace std;

int main(){
    int N;
    cin >>N;
    int k[N],p[N];
    for(int a= 0;a<N;++a){
    cin >>k[a]>>p[a];
    }
    for(int i =0;i<N;++i){
        if(k[i]%p[i]==0){
            cout <<p[i]<<endl;
    }
        else{ cout << k[i]%p[i] <<endl;
    }
    }
    return 0;
}