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