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