#include <bits/stdc++.h>
using namespace std;
string binary_to_string(long long X) {
  std::string binary_X = std::bitset<128>(X).to_string();
  return binary_X;
}
long long string_to_binary(string binary) {
  unsigned long long decimal = std::bitset<128>(binary).to_ullong();
  return decimal;
}
void solve() {
  int n, k;
  cin >> n >> k;
  if (n <= k) {
    cout << k - n << "\n";
  } else {
    if ((n + k) % 2 == 0) {
      cout << "0\n";
    } else {
      cout << "1\n";
    }
  }
}
int main() {
  long long T;
  cin >> T;
  while (T--) {
    solve();
  }
}
