#include <bits/stdc++.h>
using namespace std;
const long long NR = 1e5 + 10, oo = 1e17 + 10, MOD1 = 1e9 + 7;
const long double pi = 2 * acos(0.0);
int t;
long long n, k;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n >> k;
    if (k <= n) {
      if (n % 2 == k % 2)
        cout << "0\n";
      else
        cout << "1\n";
    } else
      cout << k - n << '\n';
  }
  return 0;
}
