#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const int N = 1e6 + 7;
int main() {
  int tt;
  scanf("%d", &tt);
  while (tt--) {
    int a, k;
    scanf("%d", &a);
    scanf("%d", &k);
    int x1 = 0;
    if (k == 0) {
      if (a % 2 != 0) x1 = 1;
    } else {
      if (k > a) x1 = abs(k - a);
      if (a > k) x1 = (a + k) % 2;
    }
    printf("%d\n", (int)x1);
  }
  return 0;
}
