#include #include #include #include #include #include #include using namespace std; typedef long long int ll; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int q; cin >> q; while(q--){ ll n,k; cin >> n >> k; if(k==1){ cout << n-1 << endl; continue; } ll res=0; ll d=k; while((d-1)