#include using namespace std; using ll = long long; using lll = __int128; using P = pair; #define fix(x) fixed << setprecision(x) #define asc(x) x, vector, greater #define rep(i, n) for(ll i = 0; i < n; ++i) #define all(x) (x).begin(),(x).end() templatebool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;} templatebool chmax(T&a, const T&b){if(a>= 1; } return res; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int t; cin >> t; while(t--){ ll n,m; cin >> n >> m; cout << f(n%m) << '\n'; } return 0; }