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