#include <bits/stdc++.h>
using namespace std;
class Solution {
 public:
  void input(void) {
    while (~scanf("%d", &t))
      while (t--) {
        scanf("%d %d", &n, &k);
        solve(n, k);
      }
  }
  void solve(int ax, int target) {
    int ans = 0;
    if (ax >= target) {
      if ((ax + target) & 01) {
        ans = 1;
      } else {
        ans = 0;
      }
    } else {
      ans = target - ax;
    }
    otput(ans);
  }
  void otput(int x) { printf("%d\n", x); }

 private:
  int t;
  int n, k;
};
int main() {
  if (0) {
    freopen("./assets/fipt.txt", "r", stdin);
    freopen("./assets/fopt.txt", "w", stdout);
  }
  Solution sol;
  sol.input();
  return 0;
}
