#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t, n, i, k;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    if (n <= k)
      cout << k - n << endl;
    else if (k + 2 <= n && k % 2 == n % 2) {
      cout << "0" << endl;
    } else if (k + 2 <= n && k % 2 != n % 2)
      cout << "1" << endl;
    else
      cout << k + 2 - n << endl;
  }
  return 0;
}
