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