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