#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int n, k;
    cin >> n, k;
    int a[n];
    int c1 = 0, c2 = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      if (i % 2 == 0) {
        if (a[i] % 2 != 0) c1++;
      } else {
        if (a[i] % 2 == 0) c2++;
      }
    }
    if (c1 != c2) {
      cout << "-1" << endl;
    } else {
      cout << c1 << endl;
    }
  }
  return 0;
}
