#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1), E = exp(1.0), EPS = DBL_EPSILON;
const long long int MOD = (long long int)1e9 + 7, N = (int)1e5;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  for (int tc = 1; tc <= T; tc++) {
    int n, k;
    cin >> n >> k;
    if (n - k >= 0) {
      cout << (n - k) % 2 << "\n";
    } else {
      cout << abs(n - k) << "\n";
    }
  }
  return 0;
}
