#include <bits/stdc++.h>
using namespace std;
long long n, k;
void solve() {
  cin >> n >> k;
  if (n < k) {
    cout << k - n << "\n";
    return;
  }
  if ((n % 2 == 0 and k % 2 == 0) or (n % 2 == 1 and k % 2 == 1))
    cout << 0 << "\n";
  else
    cout << 1 << "\n";
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long t;
  cin >> t;
  for (long long i = 1; i <= t; i++) solve();
}
