#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
int main(void) {
  int t;
  cin >> t;
  for (int ii = 0; ii < t; ii++) {
    int x, k;
    cin >> x >> k;
    if (x < k)
      cout << k - x << endl;
    else if (x % 2 != k % 2)
      cout << 1 << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}
