#include<iostream> int main() { using namespace std; int a,b,count; cin>>count; while(count--) { cin>>a>>b; cout<<(a%+b%)%<<endl; } }