#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 << abs(n - k) << endl;
    else {
      if (n % 2 == 0) {
        if (k % 2 == 1)
          cout << 1 << endl;
        else
          cout << 0 << endl;
      } else if (n % 2 == 1) {
        if (k % 2 == 0)
          cout << 1 << endl;
        else
          cout << 0 << endl;
      }
    }
  }
  return 0;
}
