#include <bits/stdc++.h>
using namespace std;
long double pi = 2 * acos(0.0);
const long long mod = 1e9 + 7;
void solve() {
  long long n, k;
  cin >> n >> k;
  if (n == 0) {
    cout << k << "\n";
    return;
  }
  if (k >= n)
    cout << k - n << "\n";
  else if ((k & 1) == (n & 1))
    cout << "0\n";
  else
    cout << "1\n";
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(nullptr);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
