#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void bober() {
  int n, k, ans = 0;
  cin >> n >> k;
  if (n < k) {
    ans = k - n;
    n = k;
  }
  if ((n - k) % 2 != 0) ans++;
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    bober();
  }
  return 0;
}
