#include <bits/stdc++.h>
using namespace std;
vector<long long> sieve(long long n) {
  vector<long long> a(n + 1, 0);
  for (long long i = 3; i <= n; i += 2) a[i] = 1;
  for (long long i = 3; i <= n; i += 2) {
    if (a[i] == 1) {
      for (long long j = i * 2; j <= n; j += i) a[j] = 0;
    }
  }
  a[2] = 1;
  a[1] = a[0] = 0;
  return a;
}
long long reverse(long long n) {
  long long s = 0;
  while (n > 0) {
    long long t = n % 10;
    s = s * 10 + t;
    n /= 10;
  }
  return s;
}
int count_setbits(int N) {
  int cnt = 0;
  while (N > 0) {
    cnt += (N & 1);
    N = N >> 1;
  }
  return cnt;
}
long long power(long long x, long long y) {
  int res = 1;
  x = x % 1000000007;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % 1000000007;
    y = y >> 1;
    x = (x * x) % 1000000007;
  }
  return res;
}
void BellmanFord(vector<vector<long long> > &graph, int V, int E, int src) {
  int dis[V];
  for (int i = 0; i < V; i++) dis[i] = INT_MAX;
  dis[src] = 0;
  for (int i = 0; i < V - 1; i++) {
    for (int j = 0; j < E; j++) {
      if (dis[graph[j][0]] + graph[j][2] < dis[graph[j][1]])
        dis[graph[j][1]] = dis[graph[j][0]] + graph[j][2];
    }
  }
  for (int i = 0; i < E; i++) {
    int x = graph[i][0];
    int y = graph[i][1];
    int weight = graph[i][2];
    if (dis[x] != INT_MAX && dis[x] + weight < dis[y])
      cout << "Graph contains negative"
              " weight cycle"
           << endl;
  }
}
bool vis[100001];
vector<long long> adj[100001];
vector<long long> edges;
void dfs_modified(long long i, long long f) {
  if (i == f) return;
  vis[i] = true;
  for (long long j = 0; i < adj[j].size(); j++) {
    long long child = adj[i][j];
    if (!vis[child]) {
      dfs_modified(child, f);
    }
  }
}
void dfs(long long node) {
  vis[node] = true;
  for (long long i = 0; i < adj[node].size(); i++) {
    long long child = adj[node][i];
    if (!vis[child]) dfs(child);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> a(n);
    vector<int> check(n, 0);
    for (long long i = 0; i < n; ++i) {
      cin >> a[i];
      if (i % 2 == 1 && a[i] % 2 == 0) check[i] = 1;
      if (i % 2 == 0 && a[i] % 2 == 1) check[i] = 2;
    }
    long long ones = 0;
    long long twos = 0;
    for (long long i : check) {
      if (i == 1) ones++;
      if (i == 2) twos++;
    }
    if (ones == 0 && twos == 0)
      cout << 0 << "\n";
    else if (ones == twos)
      cout << ones << "\n";
    else {
      cout << -1 << "\n";
    }
  }
}
