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