#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const int N = (int)1e5 + 5;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int a, k;
    cin >> a >> k;
    if (a <= k)
      cout << k - a << endl;
    else
      cout << (a - k) % 2 << endl;
  }
}
long long int power(long long int a, long long int b, long long int md = mod) {
  long long int r = 1;
  while (b) {
    if (b % 2) r = (r * a) % md;
    a = (a * a) % md;
    b >>= 1;
  }
  return r;
}
