#include using namespace std;int main(){int T,N,M,K;cin>>T;while(cin>>N>>M>>K)cout<<(K%M