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