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