#include <bits/stdc++.h>
using namespace std;
int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
const int MOD = (int)1e9 + 7;
void solve() {
  long long int n, k;
  cin >> n >> k;
  if (k > n)
    cout << k - n << endl;
  else {
    if (n % 2 != k % 2)
      cout << 1 << endl;
    else
      cout << 0 << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
