#include <bits/stdc++.h>
int main() {
  int t, n, k, i, j, l, m, steps;
  scanf("%d", &t);
  for (i = 0; i < t; i++) {
    scanf("%d%d", &n, &k);
    if (k >= n) {
      steps = k - n;
    } else {
      if (k % 2 == 0 && n % 2 == 0) {
        steps = 0;
      } else if (k % 2 != 0 && n % 2 == 0) {
        steps = 1;
      } else if (k % 2 == 0 && n % 2 != 0) {
        steps = 1;
      } else {
        steps = 0;
      }
    }
    printf("%d\n", steps);
  }
  return 0;
}
