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