#include<bits/stdc++.h>
using namespace std;
void work(){
long long n, k;
cin >> n >> k;
if(k == 0){
cout << 1 << endl;
return;
}
if(k > n){
cout << 0 << endl;
return;
}
long long m = n / k, r = n % k, ans = 0;
while(m > r){
ans++;
m--;
r += k;
}
cout << ans << endl;
}
int main(){
int T;
cin.tie(0);
cout.tie(0);
cin >> T;
while(T--){
work();
}
return 0;
}