#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const int nax = 1e5 + 200;
const double mpi = acos(-1);
const double eps = 1e-10;
int dr[] = {1, -1, 0, 0, 1, -1, -1, 1};
int dc[] = {0, 0, 1, -1, 1, 1, -1, -1};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << setprecision(20) << fixed;
  int t;
  cin >> t;
  int n, k;
  while (t--) {
    cin >> n >> k;
    if (n <= k) {
      cout << k - n << '\n';
    } else {
      if (k % 2 == 0) {
        if (n % 2 == 0) {
          cout << 0 << '\n';
        } else {
          cout << 1 << '\n';
        }
      } else {
        if (n % 2 == 0) {
          cout << 1 << '\n';
        } else {
          cout << 0 << '\n';
        }
      }
    }
  }
}
