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