#include <bits/stdc++.h>
template <class C>
inline void log_c(const C& c) {}
template <class C>
inline int sz(const C& c) {
  return static_cast<int>(c.size());
}
using namespace std;
using pii = pair<int, int>;
using num = int64_t;
using pll = pair<num, num>;
const std::string eol = "\n";
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int test_case_idx;
  cin >> test_case_idx;
  while (test_case_idx--) {
    int a, x;
    cin >> a >> x;
    if (a == x) {
      cout << '0' << eol;
      continue;
    }
    if (a < x) {
      cout << (x - a) << eol;
      continue;
    }
    cout << ((x + a) % 2 ? '1' : '0') << eol;
  }
  return 0;
}
