#include <bits/stdc++.h>
using namespace std;
const int Nmax = 1000005;
const int INF = 1000000000;
const int MOD = 1000000007;
int a[Nmax], fr[Nmax];
int do_calc(int x, int p, int y) {
  if (p == 1) {
    return x;
  }
  int ans = 1;
  for (int i = 1; i <= y; i++) {
    if (1LL * ans * p > Nmax) {
      return -1;
    }
    ans *= p;
  }
  if (1LL * x * ans > Nmax) {
    return -1;
  }
  return x * ans;
}
int Pow_log(int x, int p) {
  int ans = 1;
  while (p) {
    if (p % 2) {
      ans = (1LL * ans * x) % MOD;
      p--;
    } else {
      x = (1LL * x * x) % MOD;
      p >>= 1;
    }
  }
  return ans;
}
bool isPeak(int i) { return a[i] > a[i - 1] && a[i] > a[i + 1]; }
bool isValley(int i) { return a[i] < a[i - 1] && a[i] < a[i + 1]; }
char s[Nmax];
int main() {
  int t, n, p;
  cin.sync_with_stdio(false);
  cin >> t;
  while (t--) {
    cin >> n;
    vector<int> badPos(2, 0);
    for (int i = 0; i < n; i++) {
      int x;
      cin >> x;
      if (x % 2 != i % 2) {
        badPos[i % 2]++;
      }
    }
    if (badPos[0] != badPos[1]) {
      cout << "-1\n";
    } else {
      cout << badPos[0] << "\n";
    }
  }
  return 0;
}
