#include <bits/stdc++.h>
using namespace std;
vector<long long> readVl(vector<long long> a) {
  for (auto &el : a) {
    cin >> el;
  }
  return a;
}
vector<string> readVs(vector<string> a) {
  for (auto &el : a) {
    cin >> el;
  }
  return a;
}
vector<vector<string> > readVvs(vector<vector<string> > a) {
  for (auto &el : a) {
    for (auto &x : el) cin >> x;
  }
  return a;
}
vector<vector<long long> > readVll(vector<vector<long long> > a) {
  for (auto &el : a)
    for (auto &x : el) cin >> x;
  return a;
}
vector<pair<long long, long long> > readVpl(
    vector<pair<long long, long long> > a) {
  for (auto &el : a) cin >> el.first >> el.second;
  return a;
}
void outVl(vector<long long> a) {
  for (auto &el : a) cout << el << " ";
  cout << endl;
}
void outVll(vector<vector<long long> > a) {
  for (auto &el : a) {
    for (auto &x : el) cout << x << " ";
    cout << endl;
  }
}
void outVs(vector<string> a) {
  for (auto &el : a) cout << el << endl;
}
void outVpl(vector<pair<long long, long long> > a) {
  for (auto &el : a) cout << el.first << " " << el.second << endl;
}
void solve() {
  int n;
  cin >> n;
  vector<long long> a(n);
  a = readVl(a);
  vector<long long> dif(2, 0);
  for (int i = 0; i < n; i++) {
    if (a[i] % 2 != i % 2) dif[i % 2]++;
  }
  if (dif[0] == dif[1])
    cout << dif[0] << endl;
  else
    cout << -1 << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
}
