#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
int main() {
  int t = 1, n, k;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &k);
    if (n < k)
      printf("%d\n", k - n);
    else if ((n - k) % 2 == 0)
      printf("0\n");
    else
      printf("1\n");
  }
}
