#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
bool mysort(pair<long long, long long> A, pair<long long, long long> B) {
  return A.second > B.second;
}
long long moduloMultiplication(long long a, long long b, long long mod) {
  long long res = 0;
  a %= mod;
  while (b) {
    if (b & 1) res = (res + a) % mod;
    a = (2 * a) % mod;
    b >>= 1;
  }
  return res;
}
void solve() {
  long long n, k, i, j;
  cin >> n >> k;
  if (k == 0) {
    if (n % 2 == 0)
      cout << "0\n";
    else
      cout << "1\n";
  } else {
    if (k <= n) {
      if (n == 1)
        cout << n - k << "\n";
      else {
        if ((n + k) % 2 == 0) {
          cout << "0\n";
        } else {
          cout << "1\n";
        }
      }
    } else {
      cout << k - n << "\n";
    }
  }
}
int32_t main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    auto start = high_resolution_clock::now();
    solve();
    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<seconds>(stop - start);
  }
  return 0;
}
