#include <iostream> using namespace std; int main() { int q, m, x; cin>>q; while(q--){ cin >> m >> x; if(x%m == 0) cout<<m<<endl; else cout <<(x%m)<<endl; } return 0; }