#include <bits/stdc++.h>
using namespace std;
long long int n;
int main() {
  ios_base::sync_with_stdio(false);
  long long int t;
  cin >> t;
  while (t--) {
    long long int k;
    cin >> n >> k;
    if (k >= n) {
      cout << k - n << '\n';
      continue;
    } else {
      long long int flg = 0, l = 0, r = n;
      if (n % 2 == k % 2)
        cout << "0\n";
      else
        cout << "1\n";
      continue;
    }
  }
}
