#include <bits/stdc++.h>
using namespace std;
void testcase(long long t) { cout << "Case #" << t << ": "; }
void online() {}
const long long mod = 1e9 + 7;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long T;
  cin >> T;
  for (long long t = 1; t <= T; t++) {
    long long n, k;
    cin >> n >> k;
    if (k == 0) {
      if (n % 2)
        cout << "1\n";
      else
        cout << "0\n";
      continue;
    }
    long long x = n - k;
    if (x < 0)
      cout << abs(x) << "\n";
    else if (x % 2)
      cout << "1\n";
    else
      cout << "0\n";
  }
  return 0;
}
