#include <bits/stdc++.h>
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const double pi = acos(-1);
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    int ans;
    if (n < k)
      ans = k - n;
    else {
      if (n % 2 == k % 2)
        ans = 0;
      else
        ans = 1;
    }
    cout << ans << endl;
  }
  return 0;
}
