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