#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n);
    int imp = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      a[i] = a[i] & 1;
      if (a[i]) imp++;
    }
    if (imp != n / 2) {
      cout << -1 << endl;
      continue;
    }
    int ans = 0;
    int i = 0;
    bool pos = true;
    while (i < n - 1) {
      if ((i & 1) != a[i]) {
        int at = i + 1;
        while (a[at] == (at & 1)) {
          at++;
        }
        ans++;
        i = at;
      }
      if (!pos) break;
      i++;
    }
    if (pos) cout << ans << endl;
  }
  return 0;
}
