#include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T;cin>>T; for(;T--;) { string N; int M; cin>>N>>M; long long n=0; for(char c:N) { n=(n*10+c-'0')%(2*M); } cout<