#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long a, b;
    cin >> a >> b;
    if (b == 0) {
      if (a % 2 == 0)
        cout << 0 << endl;
      else
        cout << 1 << endl;
    } else {
      if (b <= a) {
        if (a % 2 == b % 2)
          cout << 0 << endl;
        else
          cout << 1 << endl;
      } else
        cout << b - a << endl;
    }
  }
}
