#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long n, k;
    cin >> n >> k;
    long ans;
    if (k >= n)
      ans = k - n;
    else if ((n) % 2 == (k) % 2)
      ans = 0;
    else
      ans = 1;
    cout << ans << "\n";
  }
}
