#include <bits/stdc++.h>
using namespace std;
int main() {
  int te;
  cin >> te;
  for (int t = 0; t < te; t++) {
    int n, k;
    cin >> n >> k;
    if (k >= n)
      cout << k - n << endl;
    else {
      int q = k - n;
      int r;
      int c = n - k;
      if (c % 2 == 0)
        r = 0;
      else
        r = 1;
      int x = min(abs(q), r);
      cout << x << endl;
    }
  }
}
