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